aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-01-29 11:46:16 -0700
committerJack Sangdahl <[email protected]>2025-01-29 11:46:16 -0700
commit2de9d2dce0fd4de524961ad5188a95410f4432c2 (patch)
tree0da068bf95592f39f2dd4f135b0e73b689df27d0
parentad25ada54a68851b935f52f9d1bc4ec969583205 (diff)
downloadleetcode-2de9d2dce0fd4de524961ad5188a95410f4432c2.tar.gz
leetcode-2de9d2dce0fd4de524961ad5188a95410f4432c2.zip
chore: Fix vvd usages
-rw-r--r--all_path_src_target.cpp8
-rw-r--r--ancestors_node_acyclic_graph.cpp6
-rw-r--r--arithmetic_slices2.cpp2
-rw-r--r--asteroid_collision.cpp2
-rw-r--r--binary_tree_factors.cpp2
-rw-r--r--binary_tree_zigzag.cpp4
-rw-r--r--brainpower.cpp6
-rw-r--r--build_matrix_conditions.cpp6
-rw-r--r--buy_sell_stock.cpp2
-rw-r--r--cheapest_flight_k_stop.cpp8
-rw-r--r--check_existence_edge.cpp12
-rw-r--r--check_knight_config.cpp6
-rw-r--r--check_straight_line.cpp6
-rw-r--r--clone_graph.cpp2
-rw-r--r--combinations.cpp4
-rw-r--r--construct_quad_tree.cpp6
-rw-r--r--contains_virus.cpp10
-rw-r--r--count_negative_num_matrix.cpp6
-rw-r--r--count_possible_routes.cpp2
-rw-r--r--count_unreach_node.cpp6
-rw-r--r--course_schedule.cpp4
-rw-r--r--data_stream_disjoint_interval.cpp6
-rw-r--r--detonate_max_bombs.cpp12
-rw-r--r--diff_two_array.cpp8
-rw-r--r--edit_distance.cpp4
-rw-r--r--equal_row_col_pair.cpp6
-rw-r--r--erect_fence.cpp2
-rw-r--r--eventual_safe_states.cpp4
-rw-r--r--find_building_alice_bob_meet.cpp2
-rw-r--r--find_critical_edge_tree.cpp6
-rw-r--r--find_groups_farmland.cpp8
-rw-r--r--find_k_pair_sum.cpp4
-rw-r--r--find_max_sum_node_val.cpp2
-rw-r--r--find_path_graph.cpp4
-rw-r--r--find_player_zero_one_loss.cpp2
-rw-r--r--find_safest_path_grid.cpp2
-rw-r--r--find_town_judge.cpp4
-rw-r--r--frog_jump.cpp4
-rw-r--r--image_overlap.cpp2
-rw-r--r--insert_interval.cpp8
-rw-r--r--is_graph_biparite.cpp6
-rw-r--r--keys_and_rooms.cpp4
-rw-r--r--kth_element_in_stream.cpp2
-rw-r--r--largest_colour_value_graph.cpp10
-rw-r--r--last_day_cross.cpp6
-rw-r--r--longest_arithmetic_subseq.cpp2
-rw-r--r--matrix_diagonal_sum.cpp8
-rw-r--r--max_area_cake.cpp2
-rw-r--r--max_average_pass_ration.cpp2
-rw-r--r--max_len_concat_str.cpp2
-rw-r--r--max_length_pair_chain.cpp4
-rw-r--r--max_length_repeated_subarr.cpp2
-rw-r--r--max_network_rank.cpp4
-rw-r--r--max_num_events_attended2.cpp10
-rw-r--r--max_performance_team.cpp2
-rw-r--r--max_points_line.cpp4
-rw-r--r--max_product_split_bt.cpp2
-rw-r--r--max_product_word_len.cpp2
-rw-r--r--max_profit_job.cpp2
-rw-r--r--max_total_importance_road.cpp4
-rw-r--r--max_tranfer_requests.cpp8
-rw-r--r--max_val_k_coin_pile.cpp4
-rw-r--r--min_falling_path_sum.cpp6
-rw-r--r--min_fuel_report_captial.cpp10
-rw-r--r--min_jump_reach_home.cpp2
-rw-r--r--min_num_arrow_balloon.cpp4
-rw-r--r--min_num_days_disconnect_island.cpp2
-rw-r--r--min_num_vertices_node.cpp6
-rw-r--r--min_operations_x_zero.cpp2
-rw-r--r--min_path_sum.cpp8
-rw-r--r--min_score_path_city.cpp8
-rw-r--r--min_time_apples_tree.cpp4
-rw-r--r--min_time_visit_cell_grid.cpp2
-rw-r--r--modify_graph_edge_weight.cpp4
-rw-r--r--most_stones_remove.cpp4
-rw-r--r--n_ary_tree_traverse.cpp4
-rw-r--r--non_overlapping_interval.cpp8
-rw-r--r--num_closed_islands.cpp12
-rw-r--r--num_cut_pizza.cpp4
-rw-r--r--num_dice_roll_target_sum.cpp2
-rw-r--r--num_enclaves.cpp8
-rw-r--r--num_even_nums.cpp2
-rw-r--r--num_good_path.cpp6
-rw-r--r--num_music_playlists.cpp4
-rw-r--r--num_nodes_sub_tree.cpp8
-rw-r--r--num_op_connect_network.cpp12
-rw-r--r--num_squareful_arrays.cpp2
-rw-r--r--num_ways_reorder_array.cpp2
-rw-r--r--num_weak_char_game.cpp2
-rw-r--r--number_provinces.cpp8
-rw-r--r--out_of_bounds_paths.cpp2
-rw-r--r--pacific_atlantic_water_flow.cpp6
-rw-r--r--painting_walls.cpp4
-rw-r--r--palindrome_pairs.cpp4
-rw-r--r--parallel_courses3.cpp6
-rw-r--r--path_max_probability.cpp4
-rw-r--r--path_sum2.cpp6
-rw-r--r--possible_bipartition.cpp4
-rw-r--r--range_sum_query_2d.cpp2
-rw-r--r--remove_max_num_edge_traverse.cpp8
-rw-r--r--reorder_route_city_zero.cpp12
-rw-r--r--rotate_function.cpp2
-rw-r--r--search_2d_matrix.cpp4
-rw-r--r--shortest_bridge.cpp14
-rw-r--r--shortest_dist_road_addition1.cpp2
-rw-r--r--shortest_path_alternate_color.cpp8
-rw-r--r--shortest_path_binary_matrix.cpp6
-rw-r--r--shortest_path_grid_obstacle.cpp6
-rw-r--r--shortest_path_keys.cpp2
-rw-r--r--shortest_path_vis_nodes.cpp4
-rw-r--r--single_threaded_cpu.cpp4
-rw-r--r--skyline_problem.cpp4
-rw-r--r--sliding_puzzle.cpp2
-rw-r--r--snakes_ladders.cpp6
-rw-r--r--sort_items_dependencies.cpp4
-rw-r--r--spiral_matrix.cpp8
-rw-r--r--spiral_matrix2.cpp4
-rw-r--r--stone_game2.cpp2
-rw-r--r--sum_dist_tree.cpp4
-rw-r--r--sum_even_num_queries.cpp2
-rw-r--r--toeplitz_matrix.cpp6
-rw-r--r--top_k_freq_element.cpp2
-rw-r--r--uncrossed_lines.cpp2
-rw-r--r--unique_paths2.cpp4
-rw-r--r--unique_paths3.cpp6
-rw-r--r--valid_arrangement_pairs.cpp8
-rw-r--r--vertical_order_bst.cpp4
-rw-r--r--where_will_ball_fall.cpp8
-rw-r--r--word_ladder2.cpp4
-rw-r--r--zigzag_conversion.cpp2
130 files changed, 315 insertions, 315 deletions
diff --git a/all_path_src_target.cpp b/all_path_src_target.cpp
index ae261aa..4ad02ef 100644
--- a/all_path_src_target.cpp
+++ b/all_path_src_target.cpp
@@ -2,15 +2,15 @@
class Solution {
public:
- vvd(int) allPathsSourceTarget(vvd(int) & graph) {
- vvd(int) ans;
+ vvd allPathsSourceTarget(vvd & graph) {
+ vvd ans;
vector<int> path;
dfs(graph, ans, path, 0);
return ans;
}
private:
- void dfs(vvd(int) & graph, vvd(int) & ans, vector<int> &path, int curr) {
+ void dfs(vvd & graph, vvd & ans, vector<int> &path, int curr) {
path.push_back(curr);
if (curr == graph.size() - 1)
ans.push_back(path);
@@ -23,7 +23,7 @@ private:
int main() {
Solution obj;
- vvd(int) graph = {{1, 2}, {3}, {3}, {}};
+ vvd graph = {{1, 2}, {3}, {3}, {}};
for (auto i : obj.allPathsSourceTarget(graph))
for (auto j : i)
cout << j << ' ';
diff --git a/ancestors_node_acyclic_graph.cpp b/ancestors_node_acyclic_graph.cpp
index 69917c5..71b6fb7 100644
--- a/ancestors_node_acyclic_graph.cpp
+++ b/ancestors_node_acyclic_graph.cpp
@@ -35,11 +35,11 @@ public:
int main() {
Solution obj;
- vvd(int) e1 = {{0, 3}, {0, 4}, {1, 3}, {2, 4}, {2, 7},
+ vvd e1 = {{0, 3}, {0, 4}, {1, 3}, {2, 4}, {2, 7},
{3, 5}, {3, 6}, {3, 7}, {4, 6}};
- vvd(int) e2 = {{0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 2},
+ vvd e2 = {{0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 2},
{1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}};
- vvd(int) ga1 = obj.getAncestors(8, e1), ga2 = obj.getAncestors(5, e2);
+ vvd ga1 = obj.getAncestors(8, e1), ga2 = obj.getAncestors(5, e2);
for (int i = 0; i < ga1.size(); i++) {
for (int j = 0; j < ga1[0].size(); j++)
printf("%d ",
diff --git a/arithmetic_slices2.cpp b/arithmetic_slices2.cpp
index 8dd553c..38668b7 100644
--- a/arithmetic_slices2.cpp
+++ b/arithmetic_slices2.cpp
@@ -4,7 +4,7 @@ class Solution {
public:
int numberOfArithmeticSlices(vector<int> &nums) {
unordered_map<int, vector<int>> num_idx;
- vvd(int) dp(nums.size(), vector<int>(nums.size()));
+ vvd dp(nums.size(), vector<int>(nums.size()));
int ans = 0;
for (auto i = 0; i < nums.size(); ++i)
num_idx[nums[i]].push_back(i);
diff --git a/asteroid_collision.cpp b/asteroid_collision.cpp
index 3597c8a..e27f138 100644
--- a/asteroid_collision.cpp
+++ b/asteroid_collision.cpp
@@ -29,7 +29,7 @@ public:
}
}
vector<int> ans(s.size());
- for (int i = (int)s.size() - 1; i >= 0; i--) {
+ for (int i = s.size() - 1; i >= 0; i--) {
ans[i] = s.top();
s.pop();
}
diff --git a/binary_tree_factors.cpp b/binary_tree_factors.cpp
index 7813f17..fef1b69 100644
--- a/binary_tree_factors.cpp
+++ b/binary_tree_factors.cpp
@@ -20,7 +20,7 @@ public:
um[num] = ways;
ans = (ans + ways) % 1000000007;
}
- return (int)ans;
+ return ans;
}
};
diff --git a/binary_tree_zigzag.cpp b/binary_tree_zigzag.cpp
index 641fc41..186a99f 100644
--- a/binary_tree_zigzag.cpp
+++ b/binary_tree_zigzag.cpp
@@ -6,11 +6,11 @@
class Solution {
public:
- vvd(int) zigzagLevelOrder(TreeNode *root) {
+ vvd zigzagLevelOrder(TreeNode *root) {
if (!root)
return {};
queue<TreeNode *> q;
- vvd(int) ans;
+ vvd ans;
q.push(root);
int level = 0;
while (!q.empty()) {
diff --git a/brainpower.cpp b/brainpower.cpp
index 782266f..6708336 100644
--- a/brainpower.cpp
+++ b/brainpower.cpp
@@ -14,7 +14,7 @@
class Solution {
public:
- long long mostPoints(vvd(int) & questions) {
+ long long mostPoints(vvd & questions) {
int n = questions.size();
vector<long long> dp(n + 1, 0);
for (int i = n - 1; i >= 0; --i) {
@@ -30,8 +30,8 @@ public:
int main() {
Solution obj;
- vvd(int) q1 = {{3, 2}, {4, 3}, {4, 4}, {2, 5}};
- vvd(int) q2 = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
+ vvd q1 = {{3, 2}, {4, 3}, {4, 4}, {2, 5}};
+ vvd q2 = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
printf("%lld\n", obj.mostPoints(q1)); // expect: 5
printf("%lld\n", obj.mostPoints(q2)); // expect: 7
}
diff --git a/build_matrix_conditions.cpp b/build_matrix_conditions.cpp
index d49c5fe..e192dda 100644
--- a/build_matrix_conditions.cpp
+++ b/build_matrix_conditions.cpp
@@ -79,9 +79,9 @@ public:
int main() {
Solution obj;
- vvd(int) rc1 = {{1, 2}, {3, 2}}, cc1 = {{2, 1}, {3, 2}};
- vvd(int) rc2 = {{1, 2}, {2, 3}, {3, 1}, {2, 3}}, cc2 = {{2, 1}};
- vvd(int) bm1 = obj.buildMatrix(3, rc1, cc1),
+ vvd rc1 = {{1, 2}, {3, 2}}, cc1 = {{2, 1}, {3, 2}};
+ vvd rc2 = {{1, 2}, {2, 3}, {3, 1}, {2, 3}}, cc2 = {{2, 1}};
+ vvd bm1 = obj.buildMatrix(3, rc1, cc1),
bm2 = obj.buildMatrix(3, rc2, cc2);
for (int i = 0; i < bm1.size(); i++) {
for (int j = 0; j < bm1[0].size(); j++)
diff --git a/buy_sell_stock.cpp b/buy_sell_stock.cpp
index 0a5b428..122ee2a 100644
--- a/buy_sell_stock.cpp
+++ b/buy_sell_stock.cpp
@@ -7,7 +7,7 @@ public:
return 0;
if (prices.size() == 0 || prices.size() == 1)
return 0;
- vvd(int) dp(k + 1, vector<int>(prices.size()));
+ vvd dp(k + 1, vector<int>(prices.size()));
for (int i = 0; i < dp.size(); i++) {
for (int j = 0; j < dp[i].size(); j++) {
if (i == 0 || j == 0)
diff --git a/cheapest_flight_k_stop.cpp b/cheapest_flight_k_stop.cpp
index ed00b9d..84cb206 100644
--- a/cheapest_flight_k_stop.cpp
+++ b/cheapest_flight_k_stop.cpp
@@ -12,7 +12,7 @@
typedef tuple<int, int, int> tp;
class Solution {
public:
- int findCheapestPrice(int n, vvd(int) & flights, int src, int dst, int k) {
+ int findCheapestPrice(int n, vvd & flights, int src, int dst, int k) {
vector<vector<pair<int, int>>> vvp(n);
for (const auto &f : flights)
vvp[f[0]].emplace_back(f[1], f[2]);
@@ -36,10 +36,10 @@ public:
int main() {
Solution obj;
- vvd(int) flights1 = {
+ vvd flights1 = {
{0, 1, 100}, {1, 2, 100}, {2, 0, 100}, {1, 3, 600}, {2, 3, 200}};
- vvd(int) flights2 = {{0, 1, 100}, {1, 2, 100}, {0, 2, 500}};
- vvd(int) flights3 = {{0, 1, 100}, {1, 2, 100}, {0, 2, 500}};
+ vvd flights2 = {{0, 1, 100}, {1, 2, 100}, {0, 2, 500}};
+ vvd flights3 = {{0, 1, 100}, {1, 2, 100}, {0, 2, 500}};
cout << obj.findCheapestPrice(4, flights1, 0, 3, 1) << endl; // expect: 700
cout << obj.findCheapestPrice(3, flights2, 0, 2, 1) << endl; // expect: 200
cout << obj.findCheapestPrice(3, flights3, 0, 2, 0) << endl; // expect: 500
diff --git a/check_existence_edge.cpp b/check_existence_edge.cpp
index 2ad7150..c2bd8e9 100644
--- a/check_existence_edge.cpp
+++ b/check_existence_edge.cpp
@@ -31,8 +31,8 @@ public:
class Solution {
public:
- vector<bool> distanceLimitedPathsExist(int n, vvd(int) & edge_list,
- vvd(int) & queries) {
+ vector<bool> distanceLimitedPathsExist(int n, vvd & edge_list,
+ vvd & queries) {
vector<bool> ans(queries.size());
for (int i = 0; i < queries.size(); ++i)
queries[i].push_back(i);
@@ -54,11 +54,11 @@ public:
int main() {
Solution obj;
- vvd(int) el1 = {{0, 1, 2}, {1, 2, 4}, {2, 0, 8}, {1, 0, 6}};
- vvd(int) q1 = {{0, 1, 2}, {0, 2, 5}};
+ vvd el1 = {{0, 1, 2}, {1, 2, 4}, {2, 0, 8}, {1, 0, 6}};
+ vvd q1 = {{0, 1, 2}, {0, 2, 5}};
vector<bool> dlpe1 = obj.distanceLimitedPathsExist(3, el1, q1);
- vvd(int) el2 = {{0, 1, 10}, {1, 2, 5}, {2, 3, 9}, {3, 4, 13}};
- vvd(int) q2 = {{0, 4, 14}, {1, 4, 13}};
+ vvd el2 = {{0, 1, 10}, {1, 2, 5}, {2, 3, 9}, {3, 4, 13}};
+ vvd q2 = {{0, 4, 14}, {1, 4, 13}};
vector<bool> dlpe2 = obj.distanceLimitedPathsExist(5, el2, q2);
for (int i = 0; i < 2; i++)
cout << dlpe1[i] << ' '; // expect: 0 1
diff --git a/check_knight_config.cpp b/check_knight_config.cpp
index 0fb83c1..1d97495 100644
--- a/check_knight_config.cpp
+++ b/check_knight_config.cpp
@@ -18,7 +18,7 @@
class Solution {
public:
- bool checkValidGrid(vvd(int) & grid) {
+ bool checkValidGrid(vvd & grid) {
int dir[8][2] = {{1, -2}, {2, -1}, {2, 1}, {1, 2},
{-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}};
int cnt = 0, max_cnt = grid.size() * grid.size() - 1;
@@ -48,12 +48,12 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{0, 11, 16, 5, 20},
+ vvd g1 = {{0, 11, 16, 5, 20},
{17, 4, 19, 10, 15},
{12, 1, 8, 21, 6},
{3, 18, 23, 14, 9},
{24, 13, 2, 7, 22}};
- vvd(int) g2 = {{0, 3, 6}, {5, 8, 1}, {2, 7, 4}};
+ vvd g2 = {{0, 3, 6}, {5, 8, 1}, {2, 7, 4}};
printf("%d\n", obj.checkValidGrid(g1)); // expect: 1
printf("%d\n", obj.checkValidGrid(g2)); // expect: 0
}
diff --git a/check_straight_line.cpp b/check_straight_line.cpp
index 1319b73..745738b 100644
--- a/check_straight_line.cpp
+++ b/check_straight_line.cpp
@@ -9,7 +9,7 @@
class Solution {
public:
- bool checkStraightLine(vvd(int) & coordinates) {
+ bool checkStraightLine(vvd & coordinates) {
int n = coordinates.size();
if (n == 1)
return false;
@@ -28,8 +28,8 @@ public:
int main() {
Solution obj;
- vvd(int) c1 = {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}};
- vvd(int) c2 = {{1, 1}, {2, 2}, {3, 4}, {4, 5}, {5, 6}, {7, 7}};
+ vvd c1 = {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}};
+ vvd c2 = {{1, 1}, {2, 2}, {3, 4}, {4, 5}, {5, 6}, {7, 7}};
printf("%d\n", obj.checkStraightLine(c1)); // expect: 1
printf("%d\n", obj.checkStraightLine(c2)); // expect: 0
}
diff --git a/clone_graph.cpp b/clone_graph.cpp
index 1564856..fc372a0 100644
--- a/clone_graph.cpp
+++ b/clone_graph.cpp
@@ -5,7 +5,7 @@
using namespace std;
// given reference of a node in a connected undirected graph. return a deep copy
-// (clone) of the graph. each node in the graph contains a value (int) and a
+// (clone) of the graph. each node in the graph contains a value and a
// list (list[node]).
class Node {
diff --git a/combinations.cpp b/combinations.cpp
index f524fc2..94d4bfc 100644
--- a/combinations.cpp
+++ b/combinations.cpp
@@ -9,8 +9,8 @@
class Solution {
public:
- vvd(int) combine(int n, int k) {
- vvd(int) ans;
+ vvd combine(int n, int k) {
+ vvd ans;
int i = 0;
vector<int> p(k, 0);
while (i >= 0) {
diff --git a/construct_quad_tree.cpp b/construct_quad_tree.cpp
index 3fdf395..845cefe 100644
--- a/construct_quad_tree.cpp
+++ b/construct_quad_tree.cpp
@@ -44,7 +44,7 @@ public:
class Solution {
public:
- Node *construct(vvd(int) & grid) {
+ Node *construct(vvd & grid) {
grid_v = move(grid);
leafNodes_a[0] = new Node(false, true, nullptr, nullptr, nullptr, nullptr);
leafNodes_a[1] = new Node(true, true, nullptr, nullptr, nullptr, nullptr);
@@ -52,7 +52,7 @@ public:
}
private:
- vvd(int) grid_v;
+ vvd grid_v;
array<Node *, 2> leafNodes_a;
Node *construct(int r, int c, int s) {
if (s == 1)
@@ -70,6 +70,6 @@ private:
int main() {
Solution obj;
- vvd(int) grid = {{0, 1}, {1, 0}};
+ vvd grid = {{0, 1}, {1, 0}};
cout << obj.construct(grid); // expect: [[0,1],[1,0],[1,1],[1,1],[1,0]]
}
diff --git a/contains_virus.cpp b/contains_virus.cpp
index 4380995..d0040c5 100644
--- a/contains_virus.cpp
+++ b/contains_virus.cpp
@@ -10,7 +10,7 @@ public:
class Solution {
public:
- int containsVirus(vvd(int) & isInfected) {
+ int containsVirus(vvd & isInfected) {
int n = isInfected.size(), m = isInfected[0].size(), ans = 0;
while (1) {
vvd(bool) vis(n, vector<bool>(m));
@@ -43,7 +43,7 @@ public:
}
private:
- void dfs(vvd(int) & grid, int i, int j, vvd(bool) & vis, Cluster &cl) {
+ void dfs(vvd & grid, int i, int j, vvd(bool) & vis, Cluster &cl) {
if (i == grid.size() || i < 0 || j < 0 || j == grid[0].size() ||
vis[i][j] || grid[i][j] == -1)
return;
@@ -63,12 +63,12 @@ private:
int main() {
Solution obj;
- vvd(int) isInfected1 = {{0, 1, 0, 0, 0, 0, 0, 1},
+ vvd isInfected1 = {{0, 1, 0, 0, 0, 0, 0, 1},
{0, 1, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 0}};
- vvd(int) isInfected2 = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}};
- vvd(int) isInfected3 = {{1, 1, 1, 0, 0, 0, 0, 0, 0},
+ vvd isInfected2 = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}};
+ vvd isInfected3 = {{1, 1, 1, 0, 0, 0, 0, 0, 0},
{1, 0, 1, 0, 1, 1, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 0}};
cout << obj.containsVirus(isInfected1) << endl; // expect: 10
diff --git a/count_negative_num_matrix.cpp b/count_negative_num_matrix.cpp
index 2496cf8..f7c776d 100644
--- a/count_negative_num_matrix.cpp
+++ b/count_negative_num_matrix.cpp
@@ -6,7 +6,7 @@
class Solution {
public:
- int countNegatives(vvd(int) & grid) {
+ int countNegatives(vvd & grid) {
int ans = 0;
for (vector<int> row : grid)
for (int i : row)
@@ -29,9 +29,9 @@ public:
int main() {
Solution obj;
- vvd(int)
+ vvd
g1 = {{4, 3, 2, -1}, {3, 2, 1, -1}, {1, 1, -1, -2}, {-1, -1, -2, -3}};
- vvd(int) g2 = {{3, 2}, {1, 0}};
+ vvd g2 = {{3, 2}, {1, 0}};
printf("%d\n", obj.countNegatives(g1)); // expect: 8
printf("%d\n", obj.countNegatives(g2)); // expect: 0
}
diff --git a/count_possible_routes.cpp b/count_possible_routes.cpp
index 3ab5f17..228fb2e 100644
--- a/count_possible_routes.cpp
+++ b/count_possible_routes.cpp
@@ -19,7 +19,7 @@ class Solution {
public:
int countRoutes(vector<int> &locations, int start, int finish, int fuel) {
int n = locations.size(), mod = 1e9 + 7, ans = 0;
- vvd(int) dp(n, vector<int>(fuel + 1));
+ vvd dp(n, vector<int>(fuel + 1));
dp[start][fuel] = 1;
for (int f = fuel; f >= 0; f--)
for (int i = 0; i < n; i++)
diff --git a/count_unreach_node.cpp b/count_unreach_node.cpp
index 6dba88e..bf7413b 100644
--- a/count_unreach_node.cpp
+++ b/count_unreach_node.cpp
@@ -10,7 +10,7 @@
class Solution {
public:
- long long countPairs(int n, vvd(int) & edges) {
+ long long countPairs(int n, vvd & edges) {
unordered_map<int, vector<int>> m;
for (int i = 0; i < edges.size(); i++) {
m[edges[i][0]].push_back(edges[i][0]);
@@ -41,8 +41,8 @@ private:
int main() {
Solution obj;
- vvd(int) e1 = {{0, 1}, {0, 2}, {1, 2}};
- vvd(int) e2 = {{0, 2}, {0, 5}, {2, 4}};
+ vvd e1 = {{0, 1}, {0, 2}, {1, 2}};
+ vvd e2 = {{0, 2}, {0, 5}, {2, 4}};
printf("%lld\n", obj.countPairs(3, e1)); // expect: 0
printf("%lld\n", obj.countPairs(7, e2)); // expect: 14
}
diff --git a/course_schedule.cpp b/course_schedule.cpp
index 610ab88..4a249d2 100644
--- a/course_schedule.cpp
+++ b/course_schedule.cpp
@@ -24,7 +24,7 @@ class Solution {
}
public:
- bool canFinish(int num_courses, vvd(int) & prerequisites) {
+ bool canFinish(int num_courses, vvd & prerequisites) {
vector<int> adj[num_courses];
for (auto edge : prerequisites)
adj[edge[1]].push_back(edge[0]);
@@ -38,7 +38,7 @@ public:
int main() {
Solution obj;
- vvd(int) p1 = {{1, 0}}, p2 = {{1, 0}, {0, 1}};
+ vvd p1 = {{1, 0}}, p2 = {{1, 0}, {0, 1}};
printf("%d\n", obj.canFinish(2, p1)); // expect: 1
printf("%d\n", obj.canFinish(2, p2)); // expect: 0
}
diff --git a/data_stream_disjoint_interval.cpp b/data_stream_disjoint_interval.cpp
index 7abbdeb..3682ee2 100644
--- a/data_stream_disjoint_interval.cpp
+++ b/data_stream_disjoint_interval.cpp
@@ -26,8 +26,8 @@ public:
m[mn] = mx;
m[mx] = mn;
}
- vvd(int) getIntervals() {
- vvd(int) ans;
+ vvd getIntervals() {
+ vvd ans;
auto it = m.begin();
while (it != m.end()) {
ans.push_back({it->first, it->second});
@@ -41,5 +41,5 @@ int main() {
SummaryRanges *obj = new SummaryRanges();
int value;
obj->addNum(value);
- vvd(int) param_2 = obj->getIntervals();
+ vvd param_2 = obj->getIntervals();
}
diff --git a/detonate_max_bombs.cpp b/detonate_max_bombs.cpp
index 3a1e803..4d92b98 100644
--- a/detonate_max_bombs.cpp
+++ b/detonate_max_bombs.cpp
@@ -14,7 +14,7 @@
*/
class Solution {
- void dfs(vvd(int) & graph, vector<bool> &visited, int c, int i) {
+ void dfs(vvd & graph, vector<bool> &visited, int c, int i) {
visited[i] = true;
c++;
for (int j = 0; j < graph[i].size(); j++)
@@ -23,9 +23,9 @@ class Solution {
}
public:
- int maximumDetonation(vvd(int) & bombs) {
+ int maximumDetonation(vvd & bombs) {
int n = bombs.size(), ans = INT_MIN;
- vvd(int) graph(n);
+ vvd graph(n);
for (int i = 0; i < n; i++) {
long long int x1, y1, r1;
x1 = bombs[i][0];
@@ -52,9 +52,9 @@ public:
int main() {
Solution obj;
- vvd(int) b1 = {{2, 1, 3}, {6, 1, 4}};
- vvd(int) b2 = {{1, 1, 5}, {10, 10, 5}};
- vvd(int) b3 = {{1, 2, 3}, {2, 3, 1}, {3, 4, 2}, {4, 5, 3}, {5, 6, 4}};
+ vvd b1 = {{2, 1, 3}, {6, 1, 4}};
+ vvd b2 = {{1, 1, 5}, {10, 10, 5}};
+ vvd b3 = {{1, 2, 3}, {2, 3, 1}, {3, 4, 2}, {4, 5, 3}, {5, 6, 4}};
printf("%d\n", obj.maximumDetonation(b1)); // expect: 2
printf("%d\n", obj.maximumDetonation(b2)); // expect: 1
printf("%d\n", obj.maximumDetonation(b3)); // expect: 5
diff --git a/diff_two_array.cpp b/diff_two_array.cpp
index 65bbd2a..6695ae7 100644
--- a/diff_two_array.cpp
+++ b/diff_two_array.cpp
@@ -13,9 +13,9 @@
class Solution {
public:
- vvd(int) findDifference(vector<int> &n1, vector<int> &n2) {
+ vvd findDifference(vector<int> &n1, vector<int> &n2) {
unordered_set<int> us1(begin(n1), end(n1)), us2(begin(n2), end(n2));
- vvd(int) ans(2);
+ vvd ans(2);
for (int i : us1)
if (!us2.count(i))
ans[0].push_back(i);
@@ -30,6 +30,6 @@ int main() {
Solution obj;
vector<int> n11 = {1, 2, 3}, n21 = {2, 4, 6};
vector<int> n12 = {1, 2, 3, 3}, n22 = {1, 1, 2, 2};
- vvd(int) fd1 = obj.findDifference(n11, n21);
- vvd(int) fd2 = obj.findDifference(n12, n22);
+ vvd fd1 = obj.findDifference(n11, n21);
+ vvd fd2 = obj.findDifference(n12, n22);
}
diff --git a/edit_distance.cpp b/edit_distance.cpp
index 080df8d..4103e83 100644
--- a/edit_distance.cpp
+++ b/edit_distance.cpp
@@ -11,12 +11,12 @@ class Solution {
public:
int minDistance(string word1, string word2) {
int m = word1.size(), n = word2.size();
- vvd(int) memo(m + 1, vector<int>(n + 1, -1));
+ vvd memo(m + 1, vector<int>(n + 1, -1));
return editDistance(word1, word2, m, n, memo);
}
private:
- int editDistance(string word1, string word2, int m, int n, vvd(int) memo) {
+ int editDistance(string word1, string word2, int m, int n, vvd memo) {
if (m == 0)
return memo[m][n] = n;
if (n == 0)
diff --git a/equal_row_col_pair.cpp b/equal_row_col_pair.cpp
index 3807c0c..426291c 100644
--- a/equal_row_col_pair.cpp
+++ b/equal_row_col_pair.cpp
@@ -10,7 +10,7 @@
class Solution {
public:
- int equalPairs(vvd(int) & grid) {
+ int equalPairs(vvd & grid) {
int ans = 0;
map<vector<int>, int> mv;
for (int i = 0; i < grid.size(); i++)
@@ -27,8 +27,8 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{3, 2, 1}, {1, 7, 6}, {2, 7, 7}};
- vvd(int) g2 = {{3, 1, 2, 2}, {1, 4, 4, 5}, {2, 4, 2, 2}, {2, 4, 2, 2}};
+ vvd g1 = {{3, 2, 1}, {1, 7, 6}, {2, 7, 7}};
+ vvd g2 = {{3, 1, 2, 2}, {1, 4, 4, 5}, {2, 4, 2, 2}, {2, 4, 2, 2}};
printf("%d\n", obj.equalPairs(g1)); // expect: 1
printf("%d\n", obj.equalPairs(g2)); // expect: 3
}
diff --git a/erect_fence.cpp b/erect_fence.cpp
index e68948b..9d26fb9 100644
--- a/erect_fence.cpp
+++ b/erect_fence.cpp
@@ -25,5 +25,5 @@ public:
int main() {
Solution obj;
- vvd(int) trees = {{1, 1}, {2, 2}, {2, 0}, {2, 4}, {3, 3}, {4, 2}};
+ vvd trees = {{1, 1}, {2, 2}, {2, 0}, {2, 4}, {3, 3}, {4, 2}};
}
diff --git a/eventual_safe_states.cpp b/eventual_safe_states.cpp
index 2a79b77..6e41e3e 100644
--- a/eventual_safe_states.cpp
+++ b/eventual_safe_states.cpp
@@ -43,8 +43,8 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{1, 2}, {2, 3}, {5}, {0}, {5}, {}, {}};
- vvd(int) g2 = {{1, 2, 3, 4}, {1, 2}, {3, 4}, {0, 4}, {}};
+ vvd g1 = {{1, 2}, {2, 3}, {5}, {0}, {5}, {}, {}};
+ vvd g2 = {{1, 2, 3, 4}, {1, 2}, {3, 4}, {0, 4}, {}};
for (auto i : obj.eventualSafeNodes(g1))
printf("%d ", i); // expect: 2 4 5 6
printf("\n");
diff --git a/find_building_alice_bob_meet.cpp b/find_building_alice_bob_meet.cpp
index 9067bcf..2288095 100644
--- a/find_building_alice_bob_meet.cpp
+++ b/find_building_alice_bob_meet.cpp
@@ -46,7 +46,7 @@ public:
int main() {
Solution obj;
vector<int> h1 = {6, 4, 8, 5, 2, 7}, h2 = {5, 3, 8, 2, 6, 1, 4, 6};
- vvd(int) q1 = {{0, 1}, {0, 3}, {2, 4}, {3, 4}, {2, 2}},
+ vvd q1 = {{0, 1}, {0, 3}, {2, 4}, {3, 4}, {2, 2}},
q2 = {{0, 7}, {3, 5}, {5, 2}, {3, 0}, {1, 6}};
vector<int> lmbq1 = obj.leftmostBuildingQueries(h1, q1);
vector<int> lmbq2 = obj.leftmostBuildingQueries(h2, q2);
diff --git a/find_critical_edge_tree.cpp b/find_critical_edge_tree.cpp
index 31c0338..898fd81 100644
--- a/find_critical_edge_tree.cpp
+++ b/find_critical_edge_tree.cpp
@@ -43,7 +43,7 @@ public:
};
class Solution {
- int get_mst(const int n, const vvd(int) & edges, int block_edge,
+ int get_mst(const int n, const vvd & edges, int block_edge,
int pre_edge = -1) {
UnionFind uf(n);
int weight = 0;
@@ -67,7 +67,7 @@ class Solution {
}
public:
- vvd(int) findCriticalAndPseudoCriticalEdges(int n, vvd(int) & edges) {
+ vvd findCriticalAndPseudoCriticalEdges(int n, vvd & edges) {
for (int i = 0; i < edges.size(); ++i)
edges[i].push_back(i);
sort(
@@ -87,7 +87,7 @@ public:
int main() {
Solution obj;
- vvd(int) e1 = {{0, 1, 1}, {1, 2, 1}, {2, 3, 2}, {0, 3, 2},
+ vvd e1 = {{0, 1, 1}, {1, 2, 1}, {2, 3, 2}, {0, 3, 2},
{0, 4, 3}, {3, 4, 3}, {1, 4, 6}},
e2 = {{0, 1, 1}, {1, 2, 1}, {2, 3, 1}, {0, 3, 1}};
for (auto i : obj.findCriticalAndPseudoCriticalEdges(5, e1))
diff --git a/find_groups_farmland.cpp b/find_groups_farmland.cpp
index 12b1b83..d496633 100644
--- a/find_groups_farmland.cpp
+++ b/find_groups_farmland.cpp
@@ -2,9 +2,9 @@
class Solution {
public:
- vvd(int) findFarmland(vvd(int) & land) {
+ vvd findFarmland(vvd & land) {
int n = land.size(), m = land[0].size();
- vvd(int) ans;
+ vvd ans;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (land[i][j] == 1) {
@@ -25,14 +25,14 @@ public:
int main() {
Solution obj;
- vvd(int) l1 = {{1, 0, 0},
+ vvd l1 = {{1, 0, 0},
{
0,
1,
1,
},
{0, 1, 1}};
- vvd(int) l2 = {{1, 1}, {1, 1}};
+ vvd l2 = {{1, 1}, {1, 1}};
for (auto i : obj.findFarmland(l1))
for (auto j : i)
printf("%d ", j); // expect: [[0,0,0,0],[1,1,2,2]]
diff --git a/find_k_pair_sum.cpp b/find_k_pair_sum.cpp
index a352b7e..94b779a 100644
--- a/find_k_pair_sum.cpp
+++ b/find_k_pair_sum.cpp
@@ -10,12 +10,12 @@
class Solution {
public:
- vvd(int) kSmallestPairs(vector<int> &nums1, vector<int> &nums2, int k) {
+ vvd kSmallestPairs(vector<int> &nums1, vector<int> &nums2, int k) {
priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
greater<pair<int, pair<int, int>>>>
pq;
int n = nums1.size(), m = nums2.size();
- vvd(int) ans;
+ vvd ans;
for (int i = 0; i < n; i++)
pq.push({nums1[i] + nums2[0], {i, 0}});
while (!pq.empty() && k--) {
diff --git a/find_max_sum_node_val.cpp b/find_max_sum_node_val.cpp
index d9f8fd7..60c43b8 100644
--- a/find_max_sum_node_val.cpp
+++ b/find_max_sum_node_val.cpp
@@ -35,7 +35,7 @@ public:
int main() {
Solution obj;
vector<int> n1 = {1, 2, 1}, n2 = {2, 3}, n3 = {7, 7, 7, 7, 7, 7};
- vvd(int) e1 = {{0, 1}, {0, 2}}, e2 = {{0, 1}},
+ vvd e1 = {{0, 1}, {0, 2}}, e2 = {{0, 1}},
e3 = {{0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}};
printf("%lld\n", obj.maximumValueSum(n1, 3, e1)); // expect: 6
printf("%lld\n", obj.maximumValueSum(n2, 7, e2)); // expect: 9
diff --git a/find_path_graph.cpp b/find_path_graph.cpp
index 0fae12b..9f6c8ae 100644
--- a/find_path_graph.cpp
+++ b/find_path_graph.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- bool validPath(int n, vvd(int) & edges, int source, int destination) {
+ bool validPath(int n, vvd & edges, int source, int destination) {
vector<int> ds(n, -1);
for (auto &e : edges) {
int p1 = find(ds, e[0]), p2 = find(ds, e[1]);
@@ -20,7 +20,7 @@ private:
int main() {
Solution obj;
- vvd(int) edges = {{0, 1}, {1, 2}, {2, 0}};
+ vvd edges = {{0, 1}, {1, 2}, {2, 0}};
if (obj.validPath(3, edges, 0, 2))
cout << "true";
else
diff --git a/find_player_zero_one_loss.cpp b/find_player_zero_one_loss.cpp
index 75c0e15..5aba77e 100644
--- a/find_player_zero_one_loss.cpp
+++ b/find_player_zero_one_loss.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- vvd(int) findWinners(vvd(int) & matches) {
+ vvd findWinners(vvd & matches) {
map<int, int> lost;
for (auto m : matches) {
if (!lost.count(m[0]))
diff --git a/find_safest_path_grid.cpp b/find_safest_path_grid.cpp
index 226d3c9..e6dcc3b 100644
--- a/find_safest_path_grid.cpp
+++ b/find_safest_path_grid.cpp
@@ -81,7 +81,7 @@ public:
};
int main() {
- vvd(int) g1 = {{1, 0, 0}, {0, 0, 0}, {0, 0, 1}},
+ vvd g1 = {{1, 0, 0}, {0, 0, 0}, {0, 0, 1}},
g2 = {{0, 0, 1}, {0, 0, 0}, {0, 0, 0}};
Solution obj;
printf("%d\n", obj.maximumSafenessFactor(g1)); // expect: 0
diff --git a/find_town_judge.cpp b/find_town_judge.cpp
index 70cefdf..5607688 100644
--- a/find_town_judge.cpp
+++ b/find_town_judge.cpp
@@ -12,7 +12,7 @@
class Solution {
public:
- int findJudge(int n, vvd(int) trust) {
+ int findJudge(int n, vvd trust) {
vector<unordered_set<int>> graph(n + 1, unordered_set<int>());
for (auto &edge : trust) {
int a = edge[0], b = edge[1];
@@ -38,7 +38,7 @@ public:
int main() {
Solution obj;
- vvd(int) trust1 = {{1, 2}}, trust2 = {{1, 3}, {2, 3}},
+ vvd trust1 = {{1, 2}}, trust2 = {{1, 3}, {2, 3}},
trust3 = {{1, 3}, {2, 3}, {3, 1}};
cout << obj.findJudge(2, trust1) << endl; // expect: 2
cout << obj.findJudge(3, trust2) << endl; // expect: 3
diff --git a/frog_jump.cpp b/frog_jump.cpp
index 0b40565..d9a21fc 100644
--- a/frog_jump.cpp
+++ b/frog_jump.cpp
@@ -14,7 +14,7 @@
class Solution {
bool process(vector<int> &stones, map<int, int> &mp, int i, int k,
- vvd(int) & dp) {
+ vvd & dp) {
if (i == stones.size() - 1)
return dp[i][k] = 1;
if (dp[i][k] != -1)
@@ -34,7 +34,7 @@ public:
map<int, int> mp;
for (int i = 0; i < n; i++)
mp[stones[i]] = i;
- vvd(int) dp(n + 1, vector<int>(n + 1, -1));
+ vvd dp(n + 1, vector<int>(n + 1, -1));
return process(stones, mp, 0, 0, dp);
}
};
diff --git a/image_overlap.cpp b/image_overlap.cpp
index 43527db..bc6eeba 100644
--- a/image_overlap.cpp
+++ b/image_overlap.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- int largestOverlap(vvd(int) & img1, vvd(int) & img2) {
+ int largestOverlap(vvd & img1, vvd & img2) {
vector<int> la, lb;
int n = img1.size();
unordered_map<int, int> count;
diff --git a/insert_interval.cpp b/insert_interval.cpp
index 09c6fe7..50e16f8 100644
--- a/insert_interval.cpp
+++ b/insert_interval.cpp
@@ -2,10 +2,10 @@
class Solution {
public:
- vvd(int) insert(vvd(int) & intervals, vector<int> &newInterval) {
+ vvd insert(vvd & intervals, vector<int> &newInterval) {
const int START = 0, END = 1;
int s = newInterval[START], e = newInterval[END];
- vvd(int) left, right;
+ vvd left, right;
for (auto &curr : intervals) {
if (curr[END] < s)
left.push_back(curr);
@@ -16,7 +16,7 @@ public:
e = max(e, curr[END]);
}
}
- vvd(int) ans;
+ vvd ans;
ans.insert(ans.end(), left.begin(), left.end());
ans.push_back({s, e});
ans.insert(ans.end(), right.begin(), right.end());
@@ -26,7 +26,7 @@ public:
int main() {
Solution obj;
- vvd(int) intervals1 = {{1, 3}, {6, 9}},
+ vvd intervals1 = {{1, 3}, {6, 9}},
intervals2 = {{1, 2}, {3, 5}, {6, 7}, {8, 10}, {12, 16}};
vector<int> newInterval1 = {2, 5}, newInterval2 = {4, 8};
for (auto i : obj.insert(intervals1, newInterval1))
diff --git a/is_graph_biparite.cpp b/is_graph_biparite.cpp
index 3f2f853..4a6b4fc 100644
--- a/is_graph_biparite.cpp
+++ b/is_graph_biparite.cpp
@@ -20,7 +20,7 @@
class Solution {
public:
- bool isBipartite(vvd(int) & graph) {
+ bool isBipartite(vvd & graph) {
int n = graph.size();
vector<int> colour(n);
queue<int> q;
@@ -45,8 +45,8 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{1, 2, 3}, {0, 2}, {0, 1, 3}, {0, 2}};
- vvd(int) g2 = {{1, 3}, {0, 2}, {1, 3}, {0, 2}};
+ vvd g1 = {{1, 2, 3}, {0, 2}, {0, 1, 3}, {0, 2}};
+ vvd g2 = {{1, 3}, {0, 2}, {1, 3}, {0, 2}};
printf("%d\n", obj.isBipartite(g1)); // expect: 0
printf("%d\n", obj.isBipartite(g2)); // expect: 1
}
diff --git a/keys_and_rooms.cpp b/keys_and_rooms.cpp
index d807c7c..59308ef 100644
--- a/keys_and_rooms.cpp
+++ b/keys_and_rooms.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- bool canVisitAllRooms(vvd(int) & rooms) {
+ bool canVisitAllRooms(vvd & rooms) {
stack<int> dfs;
dfs.push(0);
unordered_set<int> seen = {0};
@@ -24,7 +24,7 @@ public:
int main() {
Solution obj;
- vvd(int) rooms = {{1}, {2}, {3}, {}};
+ vvd rooms = {{1}, {2}, {3}, {}};
if (obj.canVisitAllRooms(rooms))
cout << "true";
else
diff --git a/kth_element_in_stream.cpp b/kth_element_in_stream.cpp
index 8d79bac..75e5234 100644
--- a/kth_element_in_stream.cpp
+++ b/kth_element_in_stream.cpp
@@ -8,7 +8,7 @@ private:
public:
KthLargest(int k, vector<int> &nums) {
this->k = k;
- auto endPointer = nums.begin() + min(k, (int)nums.size());
+ auto endPointer = nums.begin() + min(k, nums.size());
pq = priority_queue<int, vector<int>, greater<int>>(nums.begin(),
endPointer);
for (int i = k; i < nums.size(); ++i) {
diff --git a/largest_colour_value_graph.cpp b/largest_colour_value_graph.cpp
index 984f472..5307742 100644
--- a/largest_colour_value_graph.cpp
+++ b/largest_colour_value_graph.cpp
@@ -15,7 +15,7 @@
*/
class Solution {
- bool dfs(vvd(int) & al, vector<int> &gb, int i) {
+ bool dfs(vvd & al, vector<int> &gb, int i) {
if (!gb[i]) {
gb[i] = 1;
for (auto j : al[i])
@@ -27,14 +27,14 @@ class Solution {
}
public:
- int largestPathValue(string colours, vvd(int) & edges) {
+ int largestPathValue(string colours, vvd & edges) {
int cnt[128] = {}, colours_size = colours_size;
for (auto c : colours)
++cnt[c];
char s[26] = {};
iota(begin(s), end(s), 'a');
sort(begin(s), end(s), [&](char a, char b) { return cnt[a] > cnt[b]; });
- vvd(int) al(colours_size);
+ vvd al(colours_size);
vector<bool> target(colours_size);
for (auto &e : edges) {
al[e[0]].push_back(e[1]);
@@ -80,8 +80,8 @@ public:
int main() {
Solution obj;
- vvd(int) e1 = {{0, 1}, {0, 2}, {2, 3}, {3, 4}};
- vvd(int) e2 = {{0, 0}};
+ vvd e1 = {{0, 1}, {0, 2}, {2, 3}, {3, 4}};
+ vvd e2 = {{0, 0}};
printf("%d\n", obj.largestPathValue("abaca", e1)); // expect: 3
printf("%d\n", obj.largestPathValue("a", e2)); // expect: -1
}
diff --git a/last_day_cross.cpp b/last_day_cross.cpp
index 761e05b..4bf2e6b 100644
--- a/last_day_cross.cpp
+++ b/last_day_cross.cpp
@@ -18,8 +18,8 @@
class Solution {
public:
- int latestDayToCross(int row, int col, vvd(int) & cells) {
- vvd(int) grid(row, vector<int>(col, 1));
+ int latestDayToCross(int row, int col, vvd & cells) {
+ vvd grid(row, vector<int>(col, 1));
p = vector<int>(row * col + 3, -1);
int start_g = row * col + 1, end_g = row * col + 2;
for (int i = 0; i < col; i++) {
@@ -55,7 +55,7 @@ private:
int main() {
Solution obj;
- vvd(int) c1 = {{1, 1}, {2, 1}, {1, 2}, {2, 2}},
+ vvd c1 = {{1, 1}, {2, 1}, {1, 2}, {2, 2}},
c2 = {{1, 1}, {1, 2}, {2, 1}, {2, 2}};
printf("%d\n", obj.latestDayToCross(2, 2, c1)); // expect: 2
printf("%d\n", obj.latestDayToCross(2, 2, c2)); // expect: 1
diff --git a/longest_arithmetic_subseq.cpp b/longest_arithmetic_subseq.cpp
index 5b661db..5cc91a7 100644
--- a/longest_arithmetic_subseq.cpp
+++ b/longest_arithmetic_subseq.cpp
@@ -15,7 +15,7 @@ class Solution {
public:
int longestArithmeticSeqLength(vector<int> &nums) {
int n = nums.size(), ans = 0;
- vvd(int) dp(n, vector<int>(n, 1));
+ vvd dp(n, vector<int>(n, 1));
for (int i = 1; i < n - 1; ++i)
for (int j = i + 1; j < n; ++j) {
for (int k = i - 1; k >= 0; k--)
diff --git a/matrix_diagonal_sum.cpp b/matrix_diagonal_sum.cpp
index d5234b5..90e7fd5 100644
--- a/matrix_diagonal_sum.cpp
+++ b/matrix_diagonal_sum.cpp
@@ -10,7 +10,7 @@
class Solution {
public:
- int diagonalSum(vvd(int) & mat) {
+ int diagonalSum(vvd & mat) {
int n = mat.size(), ans = 0;
for (int i = 0; i < n; i++) {
if (i != n - i - 1)
@@ -24,9 +24,9 @@ public:
int main() {
Solution obj;
- vvd(int) m1 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
- vvd(int) m2 = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}};
- vvd(int) m3 = {{5}};
+ vvd m1 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
+ vvd m2 = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}};
+ vvd m3 = {{5}};
printf("%d\n", obj.diagonalSum(m1)); // expect: 25
printf("%d\n", obj.diagonalSum(m2)); // expect: 8
printf("%d\n", obj.diagonalSum(m3)); // expect: 5
diff --git a/max_area_cake.cpp b/max_area_cake.cpp
index f60523e..da1f745 100644
--- a/max_area_cake.cpp
+++ b/max_area_cake.cpp
@@ -12,7 +12,7 @@ public:
maxH = max(maxH, horizontalCuts[i] - horizontalCuts[i - 1]);
for (int i = 1; i < verticalCuts.size(); i++)
maxV = max(maxV, verticalCuts[i] - verticalCuts[i - 1]);
- return (int)((long)maxH * maxV % 1000000007);
+ return ((long)maxH * maxV % 1000000007);
}
};
diff --git a/max_average_pass_ration.cpp b/max_average_pass_ration.cpp
index 3da2a9f..e9ebb25 100644
--- a/max_average_pass_ration.cpp
+++ b/max_average_pass_ration.cpp
@@ -50,7 +50,7 @@ public:
int main() {
Solution obj;
- vvd(int) c1 = {{1, 2}, {3, 5}, {2, 2}},
+ vvd c1 = {{1, 2}, {3, 5}, {2, 2}},
c2 = {{2, 4}, {3, 9}, {4, 5}, {2, 10}};
printf("%f\n", obj.maxAverageRatio(c1, 2)); // expect: 0.78333
printf("%f\n", obj.maxAverageRatio(c2, 4)); // expect: 0.53485
diff --git a/max_len_concat_str.cpp b/max_len_concat_str.cpp
index e360961..b364d26 100644
--- a/max_len_concat_str.cpp
+++ b/max_len_concat_str.cpp
@@ -17,7 +17,7 @@ public:
for (int i = concat.size() - 1; i >= 0; i--)
if ((concat[i] & u).none()) {
concat.push_back(concat[i] | u);
- ans = max(ans, (int)(concat[i].count() + u.count()));
+ ans = max(ans, (concat[i].count() + u.count()));
}
return ans;
}
diff --git a/max_length_pair_chain.cpp b/max_length_pair_chain.cpp
index 7564ffb..c8ef536 100644
--- a/max_length_pair_chain.cpp
+++ b/max_length_pair_chain.cpp
@@ -13,7 +13,7 @@ class Solution {
static bool cmp(vector<int> &a, vector<int> &b) { return a[1] < b[1]; }
public:
- int findLongestChain(vvd(int) & pairs) {
+ int findLongestChain(vvd & pairs) {
sort(pairs.begin(), pairs.end(), cmp);
int cnt = 0;
for (int i = 0, j = 0; j < pairs.size(); j++)
@@ -27,7 +27,7 @@ public:
int main() {
Solution obj;
- vvd(int) p1 = {{1, 2}, {2, 3}, {3, 4}}, p2 = {{1, 2}, {7, 8}, {4, 5}};
+ vvd p1 = {{1, 2}, {2, 3}, {3, 4}}, p2 = {{1, 2}, {7, 8}, {4, 5}};
printf("%d\n", obj.findLongestChain(p1)); // expect: 2
printf("%d\n", obj.findLongestChain(p2)); // expect: 3
}
diff --git a/max_length_repeated_subarr.cpp b/max_length_repeated_subarr.cpp
index 59ab0bd..6e8ef68 100644
--- a/max_length_repeated_subarr.cpp
+++ b/max_length_repeated_subarr.cpp
@@ -4,7 +4,7 @@ class Solution {
public:
int findLength(vector<int> &nums1, vector<int> &nums2) {
int m = nums1.size(), n = nums2.size();
- vvd(int) dp(m + 1, vector<int>(n + 1));
+ vvd dp(m + 1, vector<int>(n + 1));
int ans = 0;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
diff --git a/max_network_rank.cpp b/max_network_rank.cpp
index 14a5f8f..86b0e4c 100644
--- a/max_network_rank.cpp
+++ b/max_network_rank.cpp
@@ -14,7 +14,7 @@
class Solution {
public:
- int maximalNetworkRank(int n, vvd(int) & roads) {
+ int maximalNetworkRank(int n, vvd & roads) {
vector<unordered_set<int>> graph(n);
for (auto r : roads) {
graph[r[0]].insert(r[1]);
@@ -35,7 +35,7 @@ public:
int main() {
Solution obj;
- vvd(int) r1 = {{0, 1}, {0, 3}, {1, 2}, {1, 3}},
+ vvd r1 = {{0, 1}, {0, 3}, {1, 2}, {1, 3}},
r2 = {{0, 1}, {0, 3}, {1, 2}, {1, 3}, {2, 3}, {2, 4}},
r3 = {{0, 1}, {1, 2}, {2, 3}, {2, 4}, {5, 6}, {5, 7}};
printf("%d\n", obj.maximalNetworkRank(4, r1)); // expect: 4
diff --git a/max_num_events_attended2.cpp b/max_num_events_attended2.cpp
index 4c54b9d..95c1563 100644
--- a/max_num_events_attended2.cpp
+++ b/max_num_events_attended2.cpp
@@ -14,8 +14,8 @@
*/
class Solution {
- vvd(int) dp;
- int dfs(vvd(int) & events, int k, int i) {
+ vvd dp;
+ int dfs(vvd & events, int k, int i) {
if (!k || i >= events.size())
return 0;
if (dp[i][k] != -1)
@@ -28,8 +28,8 @@ class Solution {
}
public:
- int maxValue(vvd(int) & events, int k) {
- dp = vvd(int)(events.size(), vector<int>(k + 1, -1));
+ int maxValue(vvd & events, int k) {
+ dp = vvd(events.size(), vector<int>(k + 1, -1));
sort(begin(events), end(events));
return dfs(events, k, 0);
}
@@ -37,7 +37,7 @@ public:
int main() {
Solution obj;
- vvd(int) e1 = {{1, 2, 4}, {3, 4, 3}, {2, 3, 1}},
+ vvd e1 = {{1, 2, 4}, {3, 4, 3}, {2, 3, 1}},
e2 = {{1, 2, 4}, {3, 4, 3}, {2, 3, 10}},
e3 = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}};
printf("%d\n", obj.maxValue(e1, 2)); // expect: 7
diff --git a/max_performance_team.cpp b/max_performance_team.cpp
index 07a6e6e..a7e4be8 100644
--- a/max_performance_team.cpp
+++ b/max_performance_team.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- const int mod = (int)1e9 + 7;
+ const int mod = 1e9 + 7;
int maxPerformance(int n, vector<int> &speed, vector<int> &efficiency,
int k) {
priority_queue<int, vector<int>, greater<int>> pqvg;
diff --git a/max_points_line.cpp b/max_points_line.cpp
index 5f09af7..3e34be4 100644
--- a/max_points_line.cpp
+++ b/max_points_line.cpp
@@ -11,7 +11,7 @@ public:
class Solution {
public:
- int maxPoints(vvd(int) & points) {
+ int maxPoints(vvd & points) {
int n = points.size(), ans = 0;
if (n <= 2) // 2 or less means points are always collinear
return n;
@@ -43,7 +43,7 @@ private:
int main() {
Solution obj;
- vvd(int) points1 = {{1, 1}, {2, 2}, {3, 3}},
+ vvd points1 = {{1, 1}, {2, 2}, {3, 3}},
points2 = {{1, 1}, {3, 2}, {5, 3}, {4, 1}, {2, 3}, {1, 4}};
cout << obj.maxPoints(points1) << endl; // expect: 3
cout << obj.maxPoints(points2) << endl; // expect: 4
diff --git a/max_product_split_bt.cpp b/max_product_split_bt.cpp
index f363c0e..71fc9a4 100644
--- a/max_product_split_bt.cpp
+++ b/max_product_split_bt.cpp
@@ -4,7 +4,7 @@ class Solution {
public:
int maxProduct(TreeNode *root) {
tot = solve(root), solve(root);
- return ans % (int)(1e9 + 7);
+ return ans % (1e9 + 7);
}
private:
diff --git a/max_product_word_len.cpp b/max_product_word_len.cpp
index c2e518d..e119ea1 100644
--- a/max_product_word_len.cpp
+++ b/max_product_word_len.cpp
@@ -10,7 +10,7 @@ public:
chars[i][ch - 'a'] = 1;
for (int j = 0; j < i; j++)
if (!helper(chars[i], chars[j]))
- ans = max(ans, (int)words[i].size() * (int)words[j].size());
+ ans = max(ans, words[i].size() * words[j].size());
}
return ans;
}
diff --git a/max_profit_job.cpp b/max_profit_job.cpp
index ca702c1..811874b 100644
--- a/max_profit_job.cpp
+++ b/max_profit_job.cpp
@@ -5,7 +5,7 @@ public:
int jobScheduling(vector<int> &startTime, vector<int> &endTime,
vector<int> &profit) {
int n = startTime.size();
- vvd(int) jobs;
+ vvd jobs;
for (int i = 0; i < n; ++i)
jobs.push_back({endTime[i], startTime[i], profit[i]});
sort(jobs.begin(), jobs.end());
diff --git a/max_total_importance_road.cpp b/max_total_importance_road.cpp
index 327edb2..82380ab 100644
--- a/max_total_importance_road.cpp
+++ b/max_total_importance_road.cpp
@@ -27,8 +27,8 @@ public:
int main() {
Solution obj;
- vvd(int) r1 = {{0, 1}, {1, 2}, {2, 3}, {0, 2}, {1, 3}, {2, 4}};
- vvd(int) r2 = {{0, 3}, {2, 4}, {1, 3}};
+ vvd r1 = {{0, 1}, {1, 2}, {2, 3}, {0, 2}, {1, 3}, {2, 4}};
+ vvd r2 = {{0, 3}, {2, 4}, {1, 3}};
printf("%lld\n", obj.maximumImportance(5, r1)); // expect: 43
printf("%lld\n", obj.maximumImportance(5, r2)); // expect: 20
}
diff --git a/max_tranfer_requests.cpp b/max_tranfer_requests.cpp
index c23f66b..2f0e499 100644
--- a/max_tranfer_requests.cpp
+++ b/max_tranfer_requests.cpp
@@ -14,10 +14,10 @@
class Solution {
public:
- int maximumRequests(int n, vvd(int) & requests) {
+ int maximumRequests(int n, vvd & requests) {
int ans = 0, k = requests.size(), r = 1 << k, x;
for (int i = 1; i < r; i++) {
- int *a = (int *)calloc(n, sizeof(int));
+ int *a = (int *)calloc(n, sizeof);
int curr = 0;
for (int j = 0; j < k; j++) {
if (int(i >> j) & 1) {
@@ -38,8 +38,8 @@ public:
int main() {
Solution obj;
- vvd(int) r1 = {{0, 1}, {1, 0}, {0, 1}, {1, 2}, {2, 0}, {3, 4}};
- vvd(int) r2 = {{0, 0}, {1, 2}, {2, 1}}, r3 = {{0, 3}, {3, 1}, {1, 2}, {2, 0}};
+ vvd r1 = {{0, 1}, {1, 0}, {0, 1}, {1, 2}, {2, 0}, {3, 4}};
+ vvd r2 = {{0, 0}, {1, 2}, {2, 1}}, r3 = {{0, 3}, {3, 1}, {1, 2}, {2, 0}};
printf("%d\n", obj.maximumRequests(5, r1)); // expect: 5
printf("%d\n", obj.maximumRequests(3, r2)); // expect: 3
printf("%d\n", obj.maximumRequests(4, r3)); // expect: 4
diff --git a/max_val_k_coin_pile.cpp b/max_val_k_coin_pile.cpp
index 6df457a..6452a7b 100644
--- a/max_val_k_coin_pile.cpp
+++ b/max_val_k_coin_pile.cpp
@@ -13,7 +13,7 @@
class Solution {
public:
- int maxValueOfCoins(vvd(int) & piles, int k) {
+ int maxValueOfCoins(vvd & piles, int k) {
int n = piles.size(), m[1001][2001] = {};
memset(m, -1, sizeof(m));
function<int(int, int)> dp = [&](int i, int j) {
@@ -34,7 +34,7 @@ public:
int main() {
Solution obj;
- vvd(int)
+ vvd
p1 = {{1, 100, 3}, {7, 8, 9}},
p2 = {{100}, {100}, {100}, {100}, {100}, {100}, {1, 1, 1, 1, 1, 1, 700}};
printf("%d\n", obj.maxValueOfCoins(p1, 2)); // expect: 101
diff --git a/min_falling_path_sum.cpp b/min_falling_path_sum.cpp
index 33c1cd8..3bc2940 100644
--- a/min_falling_path_sum.cpp
+++ b/min_falling_path_sum.cpp
@@ -11,8 +11,8 @@
class Solution {
public:
- int minFallingPathSum(vvd(int) & matrix) {
- vvd(int) dp(matrix.size(), vector<int>(matrix.size(), INT_MAX));
+ int minFallingPathSum(vvd & matrix) {
+ vvd dp(matrix.size(), vector<int>(matrix.size(), INT_MAX));
for (int i = 0; i < matrix.size(); i++)
dp[0][i] = matrix[0][i];
for (int i = 1; i < matrix.size(); i++) {
@@ -38,7 +38,7 @@ public:
int main() {
Solution obj;
- vvd(int) matrix = {{2, 1, 3}, // 1
+ vvd matrix = {{2, 1, 3}, // 1
{6, 5, 4}, //-> 4
{7, 8, 9}}; // 8 <-
cout << obj.minFallingPathSum(matrix); // expect 13
diff --git a/min_fuel_report_captial.cpp b/min_fuel_report_captial.cpp
index 5d13beb..4e3e2d6 100644
--- a/min_fuel_report_captial.cpp
+++ b/min_fuel_report_captial.cpp
@@ -17,8 +17,8 @@
class Solution {
public:
- long long minimumFuelCost(vvd(int) & roads, int seats) {
- vvd(int) al(roads.size() + 1);
+ long long minimumFuelCost(vvd & roads, int seats) {
+ vvd al(roads.size() + 1);
for (auto &r : roads) {
al[r[0]].push_back(r[1]);
al[r[1]].push_back(r[0]);
@@ -28,7 +28,7 @@ public:
}
private:
- long long dfs(int i, int prev, int depth, int seats, vvd(int) & al,
+ long long dfs(int i, int prev, int depth, int seats, vvd & al,
long long &ans) {
long long riders = 1;
for (int j : al[i])
@@ -43,8 +43,8 @@ private:
int main() {
Solution obj;
- vvd(int) roads1 = {{0, 1}, {0, 2}, {0, 3}};
- vvd(int) roads2 = {{3, 1}, {3, 2}, {1, 0}, {0, 4}, {0, 5}, {4, 6}};
+ vvd roads1 = {{0, 1}, {0, 2}, {0, 3}};
+ vvd roads2 = {{3, 1}, {3, 2}, {1, 0}, {0, 4}, {0, 5}, {4, 6}};
cout << obj.minimumFuelCost(roads1, 5) << endl; // expect: 3
cout << obj.minimumFuelCost(roads2, 2) << endl; // expect: 7
}
diff --git a/min_jump_reach_home.cpp b/min_jump_reach_home.cpp
index 4a66f27..7510c8c 100644
--- a/min_jump_reach_home.cpp
+++ b/min_jump_reach_home.cpp
@@ -4,7 +4,7 @@ class Solution {
public:
int minimumJumps(vector<int> &forbidden, int a, int b, int x) {
unordered_set<int> f(forbidden.begin(), forbidden.end());
- vvd(int) visited(2, vector<int>(5000));
+ vvd visited(2, vector<int>(5000));
queue<pair<int, bool>> qp;
qp.push({0, false});
visited[0][0] = 1;
diff --git a/min_num_arrow_balloon.cpp b/min_num_arrow_balloon.cpp
index fc8699f..8c79da0 100644
--- a/min_num_arrow_balloon.cpp
+++ b/min_num_arrow_balloon.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- int findMinArrowShots(vvd(int) & points) {
+ int findMinArrowShots(vvd & points) {
if (points.size() == 0)
return 0;
sort(points.begin(), points.end(), cmp);
@@ -21,7 +21,7 @@ private:
int main() {
Solution obj;
- vvd(int) points1 = {{10, 16}, {2, 8}, {1, 6}, {7, 12}},
+ vvd points1 = {{10, 16}, {2, 8}, {1, 6}, {7, 12}},
points2 = {{1, 2}, {3, 4}, {5, 6}, {7, 8}},
points3 = {{1, 2}, {2, 3}, {3, 4}, {4, 5}};
cout << obj.findMinArrowShots(points1) << endl; // expect: 2
diff --git a/min_num_days_disconnect_island.cpp b/min_num_days_disconnect_island.cpp
index 992600a..ff54c44 100644
--- a/min_num_days_disconnect_island.cpp
+++ b/min_num_days_disconnect_island.cpp
@@ -56,7 +56,7 @@ private:
int main() {
Solution obj;
- vvd(int) g1 = {{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}}, g2 = {{1, 1}};
+ vvd g1 = {{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}}, g2 = {{1, 1}};
printf("%d\n", obj.minDays(g1)); // expect: 2
printf("%d\n", obj.minDays(g2)); // expect: 2
}
diff --git a/min_num_vertices_node.cpp b/min_num_vertices_node.cpp
index d39b08b..2d53fed 100644
--- a/min_num_vertices_node.cpp
+++ b/min_num_vertices_node.cpp
@@ -11,7 +11,7 @@
class Solution {
public:
- vector<int> findSmallestSetOfVertices(int n, vvd(int) & edges) {
+ vector<int> findSmallestSetOfVertices(int n, vvd & edges) {
vector<int> ans, seen(n);
for (auto e : edges)
seen[e[1]] = 1;
@@ -24,8 +24,8 @@ public:
int main() {
Solution obj;
- vvd(int) e1 = {{0, 1}, {0, 2}, {2, 5}, {3, 4}, {4, 2}};
- vvd(int) e2 = {{0, 1}, {2, 1}, {3, 1}, {1, 4}, {2, 4}};
+ vvd e1 = {{0, 1}, {0, 2}, {2, 5}, {3, 4}, {4, 2}};
+ vvd e2 = {{0, 1}, {2, 1}, {3, 1}, {1, 4}, {2, 4}};
for (auto i : obj.findSmallestSetOfVertices(6, e1))
printf("%d ", i); // expect: 0 3
printf("\n");
diff --git a/min_operations_x_zero.cpp b/min_operations_x_zero.cpp
index a838ab9..011839e 100644
--- a/min_operations_x_zero.cpp
+++ b/min_operations_x_zero.cpp
@@ -12,7 +12,7 @@ public:
for (int i = nums.size() - 1, sum = 0; i >= 0 && sum <= x; --i) {
auto it = left.find(x - sum);
if (it != end(left) && i + 1 >= it->second)
- ans = min(ans, (int)nums.size() - i - 1 + it->second);
+ ans = min(ans, nums.size() - i - 1 + it->second);
sum += nums[i];
}
return ans = INT_MAX ? -1 : ans;
diff --git a/min_path_sum.cpp b/min_path_sum.cpp
index 2240f59..46c2ff1 100644
--- a/min_path_sum.cpp
+++ b/min_path_sum.cpp
@@ -6,9 +6,9 @@
class Solution {
public:
- int minPathSum(vvd(int) & grid) {
+ int minPathSum(vvd & grid) {
int m = grid.size(), n = grid[0].size();
- vvd(int) sum(m, vector<int>(n, grid[0][0]));
+ vvd sum(m, vector<int>(n, grid[0][0]));
for (int i = 1; i < m; i++)
sum[i][0] = sum[i - 1][0] + grid[i][0];
for (int j = 1; j < n; j++)
@@ -22,8 +22,8 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{1, 3, 1}, {1, 5, 1}, {4, 2, 1}};
- vvd(int) g2 = {{1, 2, 3}, {4, 5, 6}};
+ vvd g1 = {{1, 3, 1}, {1, 5, 1}, {4, 2, 1}};
+ vvd g2 = {{1, 2, 3}, {4, 5, 6}};
printf("%d\n", obj.minPathSum(g1)); // expect: 7
printf("%d\n", obj.minPathSum(g2)); // expect: 12
}
diff --git a/min_score_path_city.cpp b/min_score_path_city.cpp
index 5a25ec3..16f4c87 100644
--- a/min_score_path_city.cpp
+++ b/min_score_path_city.cpp
@@ -3,12 +3,12 @@
class Solution {
public:
- int minScore(int n, vvd(int) & roads) {
+ int minScore(int n, vvd & roads) {
unordered_map<int, unordered_map<int, int>> graph;
for (auto r : roads)
graph[r[0]][r[1]] = graph[r[1]][r[0]] = r[2];
unordered_set<int> vis;
- function<int(int)> dfs;
+ function<int> dfs;
dfs = [&](int n) -> int {
int res = INT_MAX;
vis.insert(n);
@@ -25,8 +25,8 @@ public:
int main() {
Solution obj;
- vvd(int) r1 = {{1, 2, 9}, {2, 3, 6}, {2, 4, 5}, {1, 4, 7}};
- vvd(int) r2 = {{1, 2, 2}, {1, 3, 4}, {3, 4, 7}};
+ vvd r1 = {{1, 2, 9}, {2, 3, 6}, {2, 4, 5}, {1, 4, 7}};
+ vvd r2 = {{1, 2, 2}, {1, 3, 4}, {3, 4, 7}};
printf("%d\n", obj.minScore(4, r1)); // expect: 5
printf("%d\n", obj.minScore(4, r2)); // expect: 2
}
diff --git a/min_time_apples_tree.cpp b/min_time_apples_tree.cpp
index 9e9d4b4..81d97d7 100644
--- a/min_time_apples_tree.cpp
+++ b/min_time_apples_tree.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- int minTime(int n, vvd(int) & edges, vector<bool> &hasApple) {
+ int minTime(int n, vvd & edges, vector<bool> &hasApple) {
unordered_map<int, int> um;
int ans = 0;
sort(edges.begin(), edges.end());
@@ -29,7 +29,7 @@ public:
int main() {
Solution obj;
- vvd(int) edges = {{0, 1}, {0, 2}, {1, 4}, {1, 5}, {2, 3}, {2, 6}};
+ vvd edges = {{0, 1}, {0, 2}, {1, 4}, {1, 5}, {2, 3}, {2, 6}};
vector<bool> hasApple1 = {false, false, true, false, true, true, false},
hasApple2 = {false, false, true, false, false, true, false},
hasApple3 = {false, false, false, false, false, false, false};
diff --git a/min_time_visit_cell_grid.cpp b/min_time_visit_cell_grid.cpp
index ce982b5..58a0099 100644
--- a/min_time_visit_cell_grid.cpp
+++ b/min_time_visit_cell_grid.cpp
@@ -45,7 +45,7 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{0, 1, 3, 2}, {5, 1, 2, 5}, {4, 3, 8, 6}},
+ vvd g1 = {{0, 1, 3, 2}, {5, 1, 2, 5}, {4, 3, 8, 6}},
g2 = {{0, 2, 4}, {3, 2, 1}, {1, 0, 4}};
printf("%d\n", obj.minimumTime(g1)); // expect: 7
printf("%d\n", obj.minimumTime(g2)); // expect: -1
diff --git a/modify_graph_edge_weight.cpp b/modify_graph_edge_weight.cpp
index 0656f5e..289098f 100644
--- a/modify_graph_edge_weight.cpp
+++ b/modify_graph_edge_weight.cpp
@@ -70,10 +70,10 @@ public:
int main() {
Solution obj;
- vvd(int) e1 = {{4, 1, -1}, {2, 0, -1}, {0, 3, -1}, {4, 3, -1}},
+ vvd e1 = {{4, 1, -1}, {2, 0, -1}, {0, 3, -1}, {4, 3, -1}},
e2 = {{0, 1, -1}, {0, 2, 5}},
e3 = {{1, 0, 4}, {1, 2, 3}, {2, 3, 5}, {0, 3, -1}};
- vvd(int) mge1 = obj.modifiedGraphEdges(5, e1, 0, 1, 5),
+ vvd mge1 = obj.modifiedGraphEdges(5, e1, 0, 1, 5),
mge2 = obj.modifiedGraphEdges(3, e2, 0, 2, 6),
mge3 = obj.modifiedGraphEdges(4, e3, 0, 2, 6);
for (int i = 0; i < mge1.size(); i++)
diff --git a/most_stones_remove.cpp b/most_stones_remove.cpp
index 632a7fc..97499f8 100644
--- a/most_stones_remove.cpp
+++ b/most_stones_remove.cpp
@@ -20,7 +20,7 @@ public:
cols[stones[i][1]].push_back(i);
}
unordered_set<int> seen;
- function<int(int)> dfs;
+ function<int> dfs;
dfs = [&](int i) -> int {
if (seen.count(i))
return 0;
@@ -40,7 +40,7 @@ public:
int main() {
Solution obj;
- vvd(int) s1 = {{0, 0}, {0, 1}, {1, 0}, {1, 2}, {2, 1}, {2, 2}},
+ vvd s1 = {{0, 0}, {0, 1}, {1, 0}, {1, 2}, {2, 1}, {2, 2}},
s2 = {{0, 1}, {0, 2}, {1, 1}, {2, 0}, {2, 2}};
printf("%d\n", obj.removeStones(s1)); // expect: 5
printf("%d\n", obj.removeStones(s2)); // expect: 3
diff --git a/n_ary_tree_traverse.cpp b/n_ary_tree_traverse.cpp
index d6cbebd..9c89682 100644
--- a/n_ary_tree_traverse.cpp
+++ b/n_ary_tree_traverse.cpp
@@ -2,8 +2,8 @@
class Solution {
public:
- vvd(int) levelOrder(Node *root) {
- vvd(int) ans;
+ vvd levelOrder(Node *root) {
+ vvd ans;
if (!root)
return ans;
queue<Node *> q;
diff --git a/non_overlapping_interval.cpp b/non_overlapping_interval.cpp
index 3cadb8d..228f691 100644
--- a/non_overlapping_interval.cpp
+++ b/non_overlapping_interval.cpp
@@ -11,7 +11,7 @@ class Solution {
static bool cmp(vector<int> &a, vector<int> &b) { return a[1] < b[1]; }
public:
- int eraseOverlapIntervals(vvd(int) & intervals) {
+ int eraseOverlapIntervals(vvd & intervals) {
int ans = -1;
if (!intervals.size())
return 0;
@@ -29,9 +29,9 @@ public:
int main() {
Solution obj;
- vvd(int) i1 = {{1, 2}, {2, 3}, {3, 4}, {1, 3}};
- vvd(int) i2 = {{1, 2}, {1, 2}, {1, 2}};
- vvd(int) i3 = {{1, 2}, {2, 3}};
+ vvd i1 = {{1, 2}, {2, 3}, {3, 4}, {1, 3}};
+ vvd i2 = {{1, 2}, {1, 2}, {1, 2}};
+ vvd i3 = {{1, 2}, {2, 3}};
printf("%d\n", obj.eraseOverlapIntervals(i1)); // expect: 1
printf("%d\n", obj.eraseOverlapIntervals(i2)); // expect: 2
printf("%d\n", obj.eraseOverlapIntervals(i3)); // expect: 0
diff --git a/num_closed_islands.cpp b/num_closed_islands.cpp
index b6a4a9e..ba0635c 100644
--- a/num_closed_islands.cpp
+++ b/num_closed_islands.cpp
@@ -10,13 +10,13 @@
class Solution {
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
- bool is_valid(vvd(int) & grid, int i, int j, int r, int c) {
+ bool is_valid(vvd & grid, int i, int j, int r, int c) {
if (i >= 0 && i < r && j >= 0 && j < c && grid[i][j] == 0)
return true;
else
return false;
}
- void dfs(vvd(int) & grid, int i, int j, int r, int c) {
+ void dfs(vvd & grid, int i, int j, int r, int c) {
grid[i][j] = 1;
for (int x = 0; x < 4; ++x) {
int new_x = i + dx[x];
@@ -27,7 +27,7 @@ class Solution {
}
public:
- int closedIsland(vvd(int) & grid) {
+ int closedIsland(vvd & grid) {
int r = grid.size(), c = grid[0].size(), ans = 0;
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
@@ -46,12 +46,12 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{1, 1, 1, 1, 1, 1, 1, 0},
+ vvd g1 = {{1, 1, 1, 1, 1, 1, 1, 0},
{1, 0, 0, 0, 0, 1, 1, 0},
{1, 0, 0, 0, 0, 1, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 0}};
- vvd(int) g2 = {{0, 0, 1, 0, 0}, {0, 1, 0, 1, 0}};
- vvd(int)
+ vvd g2 = {{0, 0, 1, 0, 0}, {0, 1, 0, 1, 0}};
+ vvd
g3 = {{1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 1}, {1, 0, 1, 1, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1}, {1, 0, 1, 1, 1, 0, 1}, {1, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1}};
diff --git a/num_cut_pizza.cpp b/num_cut_pizza.cpp
index 4f3afd7..526e21d 100644
--- a/num_cut_pizza.cpp
+++ b/num_cut_pizza.cpp
@@ -8,12 +8,12 @@
*/
class Solution {
- void add(long &a, long &b) { a = (a + b) % ((int)1e9 + 7); }
+ void add(long &a, long &b) { a = (a + b) % (1e9 + 7); }
public:
int ways(vector<string> &pizza, int k) {
int m = pizza.size(), n = pizza[0].size();
- vvd(int) cnt(m + 1, vector<int>(n + 1));
+ vvd cnt(m + 1, vector<int>(n + 1));
for (int i = m - 1; i >= 0; --i) {
int s = 0;
for (int j = n - 1; j >= 0; --j) {
diff --git a/num_dice_roll_target_sum.cpp b/num_dice_roll_target_sum.cpp
index 3fd3672..abb7596 100644
--- a/num_dice_roll_target_sum.cpp
+++ b/num_dice_roll_target_sum.cpp
@@ -4,7 +4,7 @@ class Solution {
public:
int numRollsToTarget(int n, int k, int target) {
int mod = 1000000007;
- vvd(int) dp(n + 1, vector<int>(target + 1, 0));
+ vvd dp(n + 1, vector<int>(target + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= target; j++)
diff --git a/num_enclaves.cpp b/num_enclaves.cpp
index 3c8062e..2629d65 100644
--- a/num_enclaves.cpp
+++ b/num_enclaves.cpp
@@ -11,7 +11,7 @@
*/
class Solution {
- int dfs(vvd(int) & grid, int i, int j) {
+ int dfs(vvd & grid, int i, int j) {
if (i < 0 || j < 0 || i >= grid.size() || j >= grid[0].size() ||
grid[i][j] == 0)
return 0;
@@ -21,7 +21,7 @@ class Solution {
}
public:
- int numEnclaves(vvd(int) & grid) {
+ int numEnclaves(vvd & grid) {
int ones = 0, zeros = 0;
for (int i = 0; i < grid.size(); i++)
for (int j = 0; j < grid[0].size(); j++)
@@ -38,8 +38,8 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{0, 0, 0, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}};
- vvd(int) g2 = {{0, 1, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}};
+ vvd g1 = {{0, 0, 0, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}};
+ vvd g2 = {{0, 1, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}};
printf("%d\n", obj.numEnclaves(g1)); // expect: 3
printf("%d\n", obj.numEnclaves(g2)); // expect: 0
}
diff --git a/num_even_nums.cpp b/num_even_nums.cpp
index 5d5c240..1513c72 100644
--- a/num_even_nums.cpp
+++ b/num_even_nums.cpp
@@ -16,7 +16,7 @@ public:
* it also returns n - 1. eg. log10(100) = 2
* use bitwise and to check if it's odd
*/
- ans += (int)log10(i) & 1;
+ ans += log10(i) & 1;
return ans;
}
};
diff --git a/num_good_path.cpp b/num_good_path.cpp
index 45257a7..79fae31 100644
--- a/num_good_path.cpp
+++ b/num_good_path.cpp
@@ -35,9 +35,9 @@ public:
class Solution {
public:
- int numberOfGoodPaths(vector<int> &vals, vvd(int) & edges) {
+ int numberOfGoodPaths(vector<int> &vals, vvd & edges) {
int n = vals.size(), goodPaths = 0;
- vvd(int) adj(n);
+ vvd adj(n);
map<int, vector<int>> sameVal;
for (int i = 0; i < n; i++)
sameVal[vals[i]].push_back(i);
@@ -67,7 +67,7 @@ public:
int main() {
Solution obj;
vector<int> vals1 = {1, 3, 2, 1, 3}, vals2 = {1, 1, 2, 2, 3}, vals3 = {1};
- vvd(int) edges1 = {{0, 1}, {0, 2}, {2, 3}, {2, 4}},
+ vvd edges1 = {{0, 1}, {0, 2}, {2, 3}, {2, 4}},
edges2 = {{0, 1}, {1, 2}, {2, 3}, {2, 4}}, edges3 = {};
cout << obj.numberOfGoodPaths(vals1, edges1) << endl; // expect: 6
cout << obj.numberOfGoodPaths(vals2, edges2) << endl; // expect: 7
diff --git a/num_music_playlists.cpp b/num_music_playlists.cpp
index 14e5b65..78cad3c 100644
--- a/num_music_playlists.cpp
+++ b/num_music_playlists.cpp
@@ -13,7 +13,7 @@
class Solution {
const int mod = 1e9 + 7;
- long long solve(int n, int goal, int k, vvd(int) & dp) {
+ long long solve(int n, int goal, int k, vvd & dp) {
if (!n && !goal)
return 1;
if (!n || !goal)
@@ -27,7 +27,7 @@ class Solution {
public:
int numMusicPlaylists(int n, int goal, int k) {
- vvd(int) dp(n + 1, vector<int>(goal + 1, -1));
+ vvd dp(n + 1, vector<int>(goal + 1, -1));
return solve(n, goal, k, dp);
}
};
diff --git a/num_nodes_sub_tree.cpp b/num_nodes_sub_tree.cpp
index 426c8e1..4edb9ad 100644
--- a/num_nodes_sub_tree.cpp
+++ b/num_nodes_sub_tree.cpp
@@ -2,10 +2,10 @@
class Solution {
public:
- vector<int> countSubTrees(int n, vvd(int) & edges, string labels) {
+ vector<int> countSubTrees(int n, vvd & edges, string labels) {
vector<int> ans(n);
int cnt[26] = {};
- vvd(int) i(n);
+ vvd i(n);
for (auto e : edges) {
i[e[0]].push_back(e[1]);
i[e[1]].push_back(e[0]);
@@ -15,7 +15,7 @@ public:
}
private:
- void dfs(int i, string labels, vvd(int) & edges, int cnt[],
+ void dfs(int i, string labels, vvd & edges, int cnt[],
vector<int> &ans) {
if (ans[i] == 0) {
ans[i] = 1;
@@ -32,7 +32,7 @@ private:
int main() {
Solution obj;
- vvd(int) edges1 = {{0, 1}, {0, 2}, {1, 4}, {1, 5}, {2, 3}, {2, 6}},
+ vvd edges1 = {{0, 1}, {0, 2}, {1, 4}, {1, 5}, {2, 3}, {2, 6}},
edges2 = {{0, 1}, {1, 2}, {0, 3}},
edges3 = {{0, 1}, {0, 2}, {1, 3}, {0, 4}};
for (auto i : obj.countSubTrees(7, edges1, "abaedcd"))
diff --git a/num_op_connect_network.cpp b/num_op_connect_network.cpp
index a519f66..2a9e2e4 100644
--- a/num_op_connect_network.cpp
+++ b/num_op_connect_network.cpp
@@ -3,10 +3,10 @@
class Solution {
public:
- int makeConnected(int n, vvd(int) & connections) {
+ int makeConnected(int n, vvd & connections) {
if (connections.size() < n - 1)
return -1;
- vvd(int) adj(n);
+ vvd adj(n);
for (auto v : connections) {
adj[v[0]].push_back(v[1]);
adj[v[1]].push_back(v[0]);
@@ -22,7 +22,7 @@ public:
}
private:
- void dfs(vvd(int) & adj, vector<bool> &visited, int src) {
+ void dfs(vvd & adj, vector<bool> &visited, int src) {
visited[src] = true;
for (int i : adj[src])
if (!visited[i])
@@ -32,9 +32,9 @@ private:
int main() {
Solution obj;
- vvd(int) c1 = {{0, 1}, {0, 2}, {1, 2}};
- vvd(int) c2 = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}};
- vvd(int) c3 = {{0, 1}, {0, 2}, {0, 3}, {1, 2}};
+ vvd c1 = {{0, 1}, {0, 2}, {1, 2}};
+ vvd c2 = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}};
+ vvd c3 = {{0, 1}, {0, 2}, {0, 3}, {1, 2}};
printf("%d\n", obj.makeConnected(4, c1));
printf("%d\n", obj.makeConnected(6, c2));
printf("%d\n", obj.makeConnected(6, c3));
diff --git a/num_squareful_arrays.cpp b/num_squareful_arrays.cpp
index 7d71da3..a7fc481 100644
--- a/num_squareful_arrays.cpp
+++ b/num_squareful_arrays.cpp
@@ -33,7 +33,7 @@ public:
cnt++;
}
s.push_back(cnt);
- vvd(int) f(1 << n, vector<int>(n, 0));
+ vvd f(1 << n, vector<int>(n, 0));
for (int i = 0; i < n; i++)
f[1 << i][i] = 1;
for (int S = 1; S < 1 << n; S++)
diff --git a/num_ways_reorder_array.cpp b/num_ways_reorder_array.cpp
index df5e538..9adcb55 100644
--- a/num_ways_reorder_array.cpp
+++ b/num_ways_reorder_array.cpp
@@ -45,7 +45,7 @@ class Solution {
}
public:
- int numOfWays(vector<int> &nums) { return (int)dfs(nums) - 1; }
+ int numOfWays(vector<int> &nums) { return dfs(nums) - 1; }
};
int main() {
diff --git a/num_weak_char_game.cpp b/num_weak_char_game.cpp
index f369a2a..06fa2db 100644
--- a/num_weak_char_game.cpp
+++ b/num_weak_char_game.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- int numberOfWeakCharacters(vvd(int) & properties) {
+ int numberOfWeakCharacters(vvd & properties) {
sort(properties.begin(), properties.end(), compare);
int currMax = INT_MIN, ans = 0;
for (auto p : properties) {
diff --git a/number_provinces.cpp b/number_provinces.cpp
index e267854..2f733f9 100644
--- a/number_provinces.cpp
+++ b/number_provinces.cpp
@@ -13,7 +13,7 @@
*/
class Solution {
- void dfs(int i, vvd(int) & is_connected, vector<bool> &vis) {
+ void dfs(int i, vvd & is_connected, vector<bool> &vis) {
vis[i] = true;
for (int j = 0; j < vis.size(); j++)
if (i != j && is_connected[i][j] && !vis[j])
@@ -21,7 +21,7 @@ class Solution {
}
public:
- int findCircleNum(vvd(int) & is_connected) {
+ int findCircleNum(vvd & is_connected) {
if (is_connected.empty())
return 0;
int n = is_connected.size(), groups = 0;
@@ -34,8 +34,8 @@ public:
int main() {
Solution obj;
- vvd(int) ic1 = {{1, 1, 0}, {1, 1, 0}, {0, 0, 1}};
- vvd(int) ic2 = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
+ vvd ic1 = {{1, 1, 0}, {1, 1, 0}, {0, 0, 1}};
+ vvd ic2 = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
printf("%d\n", obj.findCircleNum(ic1)); // expect: 2
printf("%d\n", obj.findCircleNum(ic2)); // expect: 3
}
diff --git a/out_of_bounds_paths.cpp b/out_of_bounds_paths.cpp
index fa19333..af5ce3f 100644
--- a/out_of_bounds_paths.cpp
+++ b/out_of_bounds_paths.cpp
@@ -20,7 +20,7 @@ public:
curr.swap(last);
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
- curr[i][j] = (int)(((long)last[i - 1][j] + last[i + 1][j] +
+ curr[i][j] = (((long)last[i - 1][j] + last[i + 1][j] +
last[i][j - 1] + last[i][j + 1]) %
1000000007L);
ans = (ans + curr[startRow + 1][startColumn + 1]) % 1000000007L;
diff --git a/pacific_atlantic_water_flow.cpp b/pacific_atlantic_water_flow.cpp
index 1bfc673..8876d9f 100644
--- a/pacific_atlantic_water_flow.cpp
+++ b/pacific_atlantic_water_flow.cpp
@@ -2,11 +2,11 @@
class Solution {
public:
- vvd(int) pacificAtlantic(vvd(int) & heights) {
+ vvd pacificAtlantic(vvd & heights) {
n = heights.size();
m = heights[0].size();
vvd(bool) flag1(n, vector<bool>(m)), flag2(n, vector<bool>(m));
- vvd(int) ans;
+ vvd ans;
for (int i = 0; i < n; i++)
dfs(heights, flag1, i, 0);
for (int i = 1; i < m; i++)
@@ -24,7 +24,7 @@ public:
private:
int n, m;
- void dfs(vvd(int) & grid, vvd(bool) & flag, int x, int y) {
+ void dfs(vvd & grid, vvd(bool) & flag, int x, int y) {
flag[x][y] = true;
if (x - 1 >= 0 && !flag[x - 1][y] && grid[x - 1][y] >= grid[x][y])
dfs(grid, flag, x - 1, y);
diff --git a/painting_walls.cpp b/painting_walls.cpp
index adcd32b..5f70012 100644
--- a/painting_walls.cpp
+++ b/painting_walls.cpp
@@ -16,7 +16,7 @@ class Solution {
public:
int paintWalls(vector<int> &cost, vector<int> &time) {
this->n = cost.size();
- vvd(int) memo(n, vector<int>(n + 1));
+ vvd memo(n, vector<int>(n + 1));
this->cost = cost;
this->time = time;
return dfs(0, n, memo);
@@ -27,7 +27,7 @@ private:
vector<int> cost;
vector<int> time;
int n;
- int dfs(int curr, int left_wall, vvd(int) & memo) {
+ int dfs(int curr, int left_wall, vvd & memo) {
if (left_wall <= 0)
return 0;
if (curr == n)
diff --git a/palindrome_pairs.cpp b/palindrome_pairs.cpp
index bc00279..8048069 100644
--- a/palindrome_pairs.cpp
+++ b/palindrome_pairs.cpp
@@ -2,14 +2,14 @@
class Solution {
public:
- vvd(int) palindromePairs(vector<string> &words) {
+ vvd palindromePairs(vector<string> &words) {
unordered_map<string, int> um;
for (int i = 0; i < words.size(); i++) {
string x = words[i];
reverse(x.begin(), x.end());
um[x] = i;
}
- vvd(int) ans;
+ vvd ans;
for (int j = 0; j < words.size(); j++) {
string str = words[j];
for (int i = 0; i <= str.size(); i++) {
diff --git a/parallel_courses3.cpp b/parallel_courses3.cpp
index 3c9e2d3..70e50e3 100644
--- a/parallel_courses3.cpp
+++ b/parallel_courses3.cpp
@@ -16,9 +16,9 @@
class Solution {
public:
- int minimumTime(int n, vvd(int) & relations, vector<int> &time) {
+ int minimumTime(int n, vvd & relations, vector<int> &time) {
vector<int> in_deg(n + 1);
- vvd(int) g(n + 1);
+ vvd g(n + 1);
for (auto r : relations) {
int a = r[0];
int b = r[1];
@@ -47,7 +47,7 @@ public:
int main() {
Solution obj;
- vvd(int) r1 = {{1, 3}, {2, 3}}, r2 = {{1, 5}, {2, 5}, {3, 5}, {3, 4}, {4, 5}};
+ vvd r1 = {{1, 3}, {2, 3}}, r2 = {{1, 5}, {2, 5}, {3, 5}, {3, 4}, {4, 5}};
vector<int> t1 = {3, 2, 5}, t2 = {1, 2, 3, 4, 5};
printf("%d\n", obj.minimumTime(3, r1, t1)); // expect: 8
printf("%d\n", obj.minimumTime(5, r2, t2)); // expect: 12
diff --git a/path_max_probability.cpp b/path_max_probability.cpp
index 0a64961..467829e 100644
--- a/path_max_probability.cpp
+++ b/path_max_probability.cpp
@@ -13,7 +13,7 @@
class Solution {
public:
- double maxProbability(int n, vvd(int) & edges, vector<double> &succ_prob,
+ double maxProbability(int n, vvd & edges, vector<double> &succ_prob,
int start, int end) {
vector<vector<pair<int, double>>> vvp(n);
for (int i = 0; i < edges.size(); i++) {
@@ -45,7 +45,7 @@ public:
int main() {
Solution obj;
- vvd(int) e1 = {{0, 1}, {1, 2}, {0, 2}}, e2 = {{0, 1}, {1, 2}, {0, 2}};
+ vvd e1 = {{0, 1}, {1, 2}, {0, 2}}, e2 = {{0, 1}, {1, 2}, {0, 2}};
vector<double> sp1 = {0.5, 0.5, 0.2}, sp2 = {0.5, 0.5, 0.3};
printf("%f\n", obj.maxProbability(3, e1, sp1, 0, 2)); // expect: 0.25000
printf("%f\n", obj.maxProbability(3, e2, sp2, 0, 2)); // expect: 0.30000
diff --git a/path_sum2.cpp b/path_sum2.cpp
index 3e64ee3..3ccfc65 100644
--- a/path_sum2.cpp
+++ b/path_sum2.cpp
@@ -2,15 +2,15 @@
class Solution {
public:
- vvd(int) pathSum(TreeNode *root, int targetSum) {
- vvd(int) ans;
+ vvd pathSum(TreeNode *root, int targetSum) {
+ vvd ans;
vector<int> d;
dfs(root, targetSum, d, ans);
return ans;
}
private:
- void dfs(TreeNode *root, int targetSum, vector<int> d, vvd(int) & ans) {
+ void dfs(TreeNode *root, int targetSum, vector<int> d, vvd & ans) {
if (root == NULL)
return;
d.push_back(root->val);
diff --git a/possible_bipartition.cpp b/possible_bipartition.cpp
index 8566e9f..6dd4175 100644
--- a/possible_bipartition.cpp
+++ b/possible_bipartition.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- bool possibleBipartition(int n, vvd(int) & dislikes) {
+ bool possibleBipartition(int n, vvd & dislikes) {
enum color { green = -1, uncolored, blue };
if (n == 1 || dislikes.size() == 0)
return true;
@@ -33,7 +33,7 @@ public:
int main() {
Solution obj;
- vvd(int) dislikes1 = {{1, 2}, {1, 3}, {2, 4}},
+ vvd dislikes1 = {{1, 2}, {1, 3}, {2, 4}},
dislikes2 = {{1, 2}, {1, 3}, {2, 3}},
dislikes3 = {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {1, 5}};
testBool(obj.possibleBipartition(4, dislikes1));
diff --git a/range_sum_query_2d.cpp b/range_sum_query_2d.cpp
index 835354f..9c77900 100644
--- a/range_sum_query_2d.cpp
+++ b/range_sum_query_2d.cpp
@@ -28,7 +28,7 @@ public:
};
int main() {
- vvd(int) matrix = {{3, 0, 1, 4, 2},
+ vvd matrix = {{3, 0, 1, 4, 2},
{5, 6, 3, 2, 1},
{1, 2, 0, 1, 5},
{4, 1, 0, 1, 7},
diff --git a/remove_max_num_edge_traverse.cpp b/remove_max_num_edge_traverse.cpp
index fb73f0b..8cc215a 100644
--- a/remove_max_num_edge_traverse.cpp
+++ b/remove_max_num_edge_traverse.cpp
@@ -21,7 +21,7 @@ public:
int find(vector<int> &ds, int i) {
return ds[i] < 0 ? i : ds[i] = find(ds, ds[i]);
}
- int maxNumEdgesToRemove(int n, vvd(int) & edges) {
+ int maxNumEdgesToRemove(int n, vvd & edges) {
vector<int> ds_both(n + 1, -1);
int used = 0;
for (int type = 3; type > 0; --type) {
@@ -48,10 +48,10 @@ public:
int main() {
Solution obj;
- vvd(int)
+ vvd
e1 = {{3, 1, 2}, {3, 2, 3}, {1, 1, 3}, {1, 2, 4}, {1, 1, 2}, {2, 3, 4}};
- vvd(int) e2 = {{3, 1, 2}, {3, 2, 3}, {1, 1, 4}, {2, 1, 4}};
- vvd(int) e3 = {{3, 2, 3}, {1, 1, 2}, {2, 3, 4}};
+ vvd e2 = {{3, 1, 2}, {3, 2, 3}, {1, 1, 4}, {2, 1, 4}};
+ vvd e3 = {{3, 2, 3}, {1, 1, 2}, {2, 3, 4}};
printf("%d\n", obj.maxNumEdgesToRemove(4, e1));
printf("%d\n", obj.maxNumEdgesToRemove(4, e2));
printf("%d\n", obj.maxNumEdgesToRemove(4, e3));
diff --git a/reorder_route_city_zero.cpp b/reorder_route_city_zero.cpp
index cce2c92..10ae61a 100644
--- a/reorder_route_city_zero.cpp
+++ b/reorder_route_city_zero.cpp
@@ -17,8 +17,8 @@
class Solution {
public:
- int minReorder(int n, vvd(int) & connections) {
- vvd(int) ans(n);
+ int minReorder(int n, vvd & connections) {
+ vvd ans(n);
for (auto &c : connections) {
ans[c[0]].push_back(c[1]);
ans[c[1]].push_back(-c[0]);
@@ -27,7 +27,7 @@ public:
}
private:
- int dfs(vvd(int) & res, vector<bool> visited, int from) {
+ int dfs(vvd & res, vector<bool> visited, int from) {
auto change = 0;
visited[from] = true;
for (auto to : res[from])
@@ -39,9 +39,9 @@ private:
int main() {
Solution obj;
- vvd(int) connections1 = {{0, 1}, {1, 3}, {2, 3}, {4, 0}, {4, 5}};
- vvd(int) connections2 = {{1, 0}, {1, 2}, {3, 2}, {3, 4}};
- vvd(int) connections3 = {{1, 0}, {2, 0}};
+ vvd connections1 = {{0, 1}, {1, 3}, {2, 3}, {4, 0}, {4, 5}};
+ vvd connections2 = {{1, 0}, {1, 2}, {3, 2}, {3, 4}};
+ vvd connections3 = {{1, 0}, {2, 0}};
cout << obj.minReorder(6, connections1) << endl; // expect: 3
cout << obj.minReorder(5, connections2) << endl; // expect: 2
cout << obj.minReorder(3, connections3) << endl; // expect: 0
diff --git a/rotate_function.cpp b/rotate_function.cpp
index d764feb..1bfd7f5 100644
--- a/rotate_function.cpp
+++ b/rotate_function.cpp
@@ -18,7 +18,7 @@ public:
fn = max(fn, newFn);
l++;
}
- return (int)fn;
+ return fn;
}
};
diff --git a/search_2d_matrix.cpp b/search_2d_matrix.cpp
index 44c42d4..3d8ce04 100644
--- a/search_2d_matrix.cpp
+++ b/search_2d_matrix.cpp
@@ -12,7 +12,7 @@
class Solution {
public:
- bool searchMatrix(vvd(int) & matrix, int target) {
+ bool searchMatrix(vvd & matrix, int target) {
int rows = matrix.size(), cols = matrix[0].size(), row = 0, col = cols - 1;
while (row < rows && col > -1) {
int curr = matrix[row][col];
@@ -29,7 +29,7 @@ public:
int main() {
Solution obj;
- vvd(int) matrix = {{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 60}};
+ vvd matrix = {{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 60}};
printf("%d\n", obj.searchMatrix(matrix, 3)); // expect: 1
printf("%d\n", obj.searchMatrix(matrix, 13)); // expect: 0
}
diff --git a/shortest_bridge.cpp b/shortest_bridge.cpp
index 632f246..818d384 100644
--- a/shortest_bridge.cpp
+++ b/shortest_bridge.cpp
@@ -11,7 +11,7 @@
class Solution {
queue<pair<int, int>> qp;
- void dfs(vvd(int) & grid, int i, int j) {
+ void dfs(vvd & grid, int i, int j) {
if (i < 0 || i >= grid.size() || j < 0 || j >= grid[0].size() ||
grid[i][j] == 2 || !grid[i][j])
return;
@@ -22,9 +22,9 @@ class Solution {
dfs(grid, i, j + 1);
dfs(grid, i, j - 1);
}
- int bfs(vvd(int) & grid) {
+ int bfs(vvd & grid) {
int d = 0, min_dist = INT_MAX;
- vvd(int) dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
+ vvd dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
while (!qp.empty()) {
int n = qp.size();
while (n--) {
@@ -49,7 +49,7 @@ class Solution {
}
public:
- int shotestBridge(vvd(int) & grid) {
+ int shotestBridge(vvd & grid) {
bool flag = false;
for (int i = 0; i < grid.size(); i++) {
for (int j = 0; j < grid[0].size(); j++) {
@@ -69,9 +69,9 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{0, 1}, {1, 0}};
- vvd(int) g2 = {{0, 1, 0}, {0, 0, 0}, {0, 0, 1}};
- vvd(int) g3 = {{1, 1, 1, 1, 1},
+ vvd g1 = {{0, 1}, {1, 0}};
+ vvd g2 = {{0, 1, 0}, {0, 0, 0}, {0, 0, 1}};
+ vvd g3 = {{1, 1, 1, 1, 1},
{1, 0, 0, 0, 1},
{1, 0, 1, 0, 1},
{1, 0, 0, 0, 1},
diff --git a/shortest_dist_road_addition1.cpp b/shortest_dist_road_addition1.cpp
index e0cc205..deea04c 100644
--- a/shortest_dist_road_addition1.cpp
+++ b/shortest_dist_road_addition1.cpp
@@ -36,7 +36,7 @@ public:
int main() {
Solution obj;
- vvd(int) q1 = {{2, 4}, {0, 2}, {0, 4}}, q2 = {{0, 3}, {0, 3}};
+ vvd q1 = {{2, 4}, {0, 2}, {0, 4}}, q2 = {{0, 3}, {0, 3}};
vector<int> sdaq1 = obj.shortestDistanceAfterQueries(5, q1);
vector<int> sdaq2 = obj.shortestDistanceAfterQueries(4, q2);
for (auto i : sdaq1)
diff --git a/shortest_path_alternate_color.cpp b/shortest_path_alternate_color.cpp
index 5122fef..a5cf369 100644
--- a/shortest_path_alternate_color.cpp
+++ b/shortest_path_alternate_color.cpp
@@ -3,8 +3,8 @@
class Solution {
public:
- vector<int> shortestAlternatingPaths(int n, vvd(int) & redEdges,
- vvd(int) & blueEdges) {
+ vector<int> shortestAlternatingPaths(int n, vvd & redEdges,
+ vvd & blueEdges) {
vector<int> ans(n, -1), v1(n, 0), v2(n, 0);
vector<vector<pair<int, int>>> vvp(n);
queue<pair<int, int>> qp;
@@ -46,8 +46,8 @@ public:
int main() {
Solution obj;
- vvd(int) re1 = {{0, 1}, {1, 2}}, be1 = {};
- vvd(int) re2 = {{0, 1}}, be2 = {{2, 1}};
+ vvd re1 = {{0, 1}, {1, 2}}, be1 = {};
+ vvd re2 = {{0, 1}}, be2 = {{2, 1}};
for (auto i : obj.shortestAlternatingPaths(3, re1, be1))
cout << i << ' '; // expect: 0 1 -1
cout << endl;
diff --git a/shortest_path_binary_matrix.cpp b/shortest_path_binary_matrix.cpp
index cbdccdc..fd586fe 100644
--- a/shortest_path_binary_matrix.cpp
+++ b/shortest_path_binary_matrix.cpp
@@ -46,9 +46,9 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{0, 1}, {1, 0}};
- vvd(int) g2 = {{0, 0, 0}, {1, 1, 0}, {1, 1, 0}};
- vvd(int) g3 = {{1, 0, 0}, {1, 1, 0}, {1, 1, 0}};
+ vvd g1 = {{0, 1}, {1, 0}};
+ vvd g2 = {{0, 0, 0}, {1, 1, 0}, {1, 1, 0}};
+ vvd g3 = {{1, 0, 0}, {1, 1, 0}, {1, 1, 0}};
printf("%d\n", obj.shortestPathBinaryMatrix(g1)); // expect: 2
printf("%d\n", obj.shortestPathBinaryMatrix(g2)); // expect: 4
printf("%d\n", obj.shortestPathBinaryMatrix(g3)); // expect: -1
diff --git a/shortest_path_grid_obstacle.cpp b/shortest_path_grid_obstacle.cpp
index a023bc3..daaa361 100644
--- a/shortest_path_grid_obstacle.cpp
+++ b/shortest_path_grid_obstacle.cpp
@@ -2,13 +2,13 @@
class Solution {
public:
- int shortestPath(vvd(int) & grid, int k) {
+ int shortestPath(vvd & grid, int k) {
int rows = grid.size(), cols = grid[0].size();
int minStep = max(0, rows + cols - 2), obstacles = minStep - 1,
minStepNext = minStep;
if (obstacles <= k)
return minStep;
- vvd(int) dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
+ vvd dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
list<vector<int>> togo;
togo.push_back({0, 0, k});
vector<int> visited(rows * cols, -1);
@@ -42,7 +42,7 @@ public:
int main() {
Solution obj;
- vvd(int) grid = {{0, 0, 0}, {1, 1, 0}, {0, 0, 0}, {0, 1, 1}, {0, 0, 0}};
+ vvd grid = {{0, 0, 0}, {1, 1, 0}, {0, 0, 0}, {0, 1, 1}, {0, 0, 0}};
int k = 1;
cout << obj.shortestPath(grid, k);
}
diff --git a/shortest_path_keys.cpp b/shortest_path_keys.cpp
index 7a3cd7d..15ffe90 100644
--- a/shortest_path_keys.cpp
+++ b/shortest_path_keys.cpp
@@ -60,7 +60,7 @@ public:
int ans = -1;
vector<vector<vector<int>>> vis;
for (int i = 0; i < 1 << key_cnt; i++) {
- vvd(int) tmp(m, vector<int>(n, 0));
+ vvd tmp(m, vector<int>(n, 0));
vis.push_back(tmp);
}
while (!q.empty()) {
diff --git a/shortest_path_vis_nodes.cpp b/shortest_path_vis_nodes.cpp
index 8ac5587..23d95ea 100644
--- a/shortest_path_vis_nodes.cpp
+++ b/shortest_path_vis_nodes.cpp
@@ -23,7 +23,7 @@ public:
}
};
- int shortestPathLength(vvd(int) & graph) {
+ int shortestPathLength(vvd & graph) {
int n = graph.size();
queue<tuple> q;
set<pair<int, int>> vis;
@@ -55,7 +55,7 @@ public:
int main() {
Solution obj;
- vvd(int) g1 = {{1, 2, 3}, {0}, {0}},
+ vvd g1 = {{1, 2, 3}, {0}, {0}},
g2 = {{1}, {0, 2, 4}, {1, 3, 4}, {2}, {1, 2}};
printf("%d\n", obj.shortestPathLength(g1)); // expect: 4
printf("%d\n", obj.shortestPathLength(g2)); // expect: 4
diff --git a/single_threaded_cpu.cpp b/single_threaded_cpu.cpp
index aaa3598..db32185 100644
--- a/single_threaded_cpu.cpp
+++ b/single_threaded_cpu.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- vector<int> getOrder(vvd(int) & tasks) {
+ vector<int> getOrder(vvd & tasks) {
vector<int> ans, idx(tasks.size());
priority_queue<pair<int, int>> pqp;
iota(begin(idx), end(idx), 0);
@@ -25,7 +25,7 @@ public:
int main() {
Solution obj;
- vvd(int) tasks = {{1, 2}, {2, 4}, {3, 2}, {4, 1}};
+ vvd tasks = {{1, 2}, {2, 4}, {3, 2}, {4, 1}};
for (auto i : obj.getOrder(tasks))
cout << i << ' '; // expect 0,2,3,1
}
diff --git a/skyline_problem.cpp b/skyline_problem.cpp
index 1828978..b19c87a 100644
--- a/skyline_problem.cpp
+++ b/skyline_problem.cpp
@@ -2,8 +2,8 @@
class Solution {
public:
- vvd(int) getSkyline(vvd(int) & buildings) {
- vvd(int) ans;
+ vvd getSkyline(vvd & buildings) {
+ vvd ans;
map<int, vector<pair<int, int>>> mvp;
for (auto &b : buildings) {
mvp[b[0]].push_back({b[2], 0});
diff --git a/sliding_puzzle.cpp b/sliding_puzzle.cpp
index 8b3ac7c..9b772f1 100644
--- a/sliding_puzzle.cpp
+++ b/sliding_puzzle.cpp
@@ -45,7 +45,7 @@ public:
int main() {
Solution obj;
- vvd(int) b1 = {{1, 2, 3}, {4, 0, 5}}, b2 = {{1, 2, 3}, {5, 4, 0}},
+ vvd b1 = {{1, 2, 3}, {4, 0, 5}}, b2 = {{1, 2, 3}, {5, 4, 0}},
b3 = {{4, 1, 2}, {5, 0, 3}};
printf("%d\n", obj.slidingPuzzle(b1)); // expect 1
printf("%d\n", obj.slidingPuzzle(b2)); // expect -1
diff --git a/snakes_ladders.cpp b/snakes_ladders.cpp
index 32f870a..160b473 100644
--- a/snakes_ladders.cpp
+++ b/snakes_ladders.cpp
@@ -4,7 +4,7 @@
typedef pair<int, int> pii;
class Solution {
public:
- int snakesAndLadders(vvd(int) & board) {
+ int snakesAndLadders(vvd & board) {
int rows = board.size(), cols = board[0].size();
int target = rows * cols, r, c, p;
vector<int> visited(rows * cols + 1); // cells on board starting from 1
@@ -38,10 +38,10 @@ public:
int main() {
Solution obj;
- vvd(int) board1 = {{-1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1},
+ vvd board1 = {{-1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1}, {-1, 35, -1, -1, 13, -1},
{-1, -1, -1, -1, -1, -1}, {-1, 15, -1, -1, -1, -1}};
- vvd(int) board2 = {{-1, -1}, {-1, 3}};
+ vvd board2 = {{-1, -1}, {-1, 3}};
cout << obj.snakesAndLadders(board1) << endl; // expect: 4
cout << obj.snakesAndLadders(board2) << endl; // expect: 1
}
diff --git a/sort_items_dependencies.cpp b/sort_items_dependencies.cpp
index 0139659..1887d05 100644
--- a/sort_items_dependencies.cpp
+++ b/sort_items_dependencies.cpp
@@ -31,7 +31,7 @@ class Solution {
public:
vector<int> sortItems(int n, int m, vector<int> &group,
- vvd(int) & beforeItems) {
+ vvd & beforeItems) {
vector<int> ans(n), stat(n + 2 * m), ans_tmp;
vector<unordered_set<int>> al(n + 2 * m);
for (auto i = 0; i < n; ++i) {
@@ -63,7 +63,7 @@ int main() {
Solution obj;
vector<int> g1 = {-1, -1, 1, 0, 0, 1, 0, -1},
g2 = {-1, -1, 1, 0, 0, 1, 0, -1};
- vvd(int) bi1 = {{}, {6}, {5}, {6}, {3, 6}, {}, {}, {}},
+ vvd bi1 = {{}, {6}, {5}, {6}, {3, 6}, {}, {}, {}},
bi2 = {{}, {6}, {5}, {6}, {3}, {}, {4}, {}};
for (auto i : obj.sortItems(8, 2, g1, bi1))
printf("%d ", i); // expect: [6,3,4,1,5,2,0,7]
diff --git a/spiral_matrix.cpp b/spiral_matrix.cpp
index ac1d212..d1c294b 100644
--- a/spiral_matrix.cpp
+++ b/spiral_matrix.cpp
@@ -5,8 +5,8 @@
class Solution {
public:
- vector<int> spiralOrder(vvd(int) & matrix) {
- vvd(int) dirs{{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
+ vector<int> spiralOrder(vvd & matrix) {
+ vvd dirs{{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int rows = matrix.size(), cols = matrix[0].size();
vector<int> ans, n_step{cols, rows - 1};
if (!rows || !cols)
@@ -27,8 +27,8 @@ public:
int main() {
Solution obj;
- vvd(int) m1 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
- vvd(int) m2 = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
+ vvd m1 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
+ vvd m2 = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
for (auto i : obj.spiralOrder(m1))
printf("%d, ", i);
printf("\n"); // expect: 1,2,3,6,9,8,7,4,5
diff --git a/spiral_matrix2.cpp b/spiral_matrix2.cpp
index de119a5..dc8dc11 100644
--- a/spiral_matrix2.cpp
+++ b/spiral_matrix2.cpp
@@ -6,8 +6,8 @@
class Solution {
public:
- vvd(int) generateMatrix(int n) {
- vvd(int) matrix(n, vector<int>(n));
+ vvd generateMatrix(int n) {
+ vvd matrix(n, vector<int>(n));
int num = 1, row = 0, col = 0, dir = 0;
vector<int> d_r = {0, 1, 0, -1}, d_c = {1, 0, -1, 0};
while (num <= n * n) {
diff --git a/stone_game2.cpp b/stone_game2.cpp
index 808546f..7ebc520 100644
--- a/stone_game2.cpp
+++ b/stone_game2.cpp
@@ -16,7 +16,7 @@ class Solution {
public:
int stoneGameII(vector<int> &piles) {
int n = piles.size();
- vvd(int) dp(n + 1, vector<int>(n + 1, 0));
+ vvd dp(n + 1, vector<int>(n + 1, 0));
vector<int> sum(n + 1, 0);
for (int i = n - 1; i >= 0; i--)
sum[i] = sum[i + 1] + piles[i];
diff --git a/sum_dist_tree.cpp b/sum_dist_tree.cpp
index 93efec8..10fc449 100644
--- a/sum_dist_tree.cpp
+++ b/sum_dist_tree.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- vector<int> sumOfDistancesInTree(int n, vvd(int) & edges) {
+ vector<int> sumOfDistancesInTree(int n, vvd & edges) {
tree.resize(n);
ans.assign(n, 0);
count.assign(n, 1);
@@ -39,7 +39,7 @@ private:
int main() {
Solution obj;
- vvd(int) edges = {{0, 1}, {0, 2}, {2, 3}, {2, 4}, {2, 5}};
+ vvd edges = {{0, 1}, {0, 2}, {2, 3}, {2, 4}, {2, 5}};
for (auto i : obj.sumOfDistancesInTree(6, edges))
cout << i << ' '; // expect: 8 12 6 10 10 10
}
diff --git a/sum_even_num_queries.cpp b/sum_even_num_queries.cpp
index 2c3b460..a58e3b2 100644
--- a/sum_even_num_queries.cpp
+++ b/sum_even_num_queries.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- vector<int> sumEvenAfterQueries(vector<int> &nums, vvd(int) & queries) {
+ vector<int> sumEvenAfterQueries(vector<int> &nums, vvd & queries) {
int evenSum = 0;
for (auto x : nums)
if (x % 2 == 0)
diff --git a/toeplitz_matrix.cpp b/toeplitz_matrix.cpp
index 8a1bec4..f451196 100644
--- a/toeplitz_matrix.cpp
+++ b/toeplitz_matrix.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- bool isToeplitzMatrix(vvd(int) & matrix) {
+ bool isToeplitzMatrix(vvd & matrix) {
int m = matrix.size(), n = matrix[0].size();
for (int i = 1; i < m; i++)
for (int j = 1; j < n; j++)
@@ -15,9 +15,9 @@ public:
int main() {
Solution obj;
// true - all diagonals have the same elements
- vvd(int) matrix = {{1, 2, 3, 4}, {5, 1, 2, 3}, {9, 5, 1, 2}};
+ vvd matrix = {{1, 2, 3, 4}, {5, 1, 2, 3}, {9, 5, 1, 2}};
// false - diagonals do not share same elements
- vvd(int) matrix2 = {{1, 2}, {2, 2}};
+ vvd matrix2 = {{1, 2}, {2, 2}};
if (obj.isToeplitzMatrix(matrix))
cout << "true";
diff --git a/top_k_freq_element.cpp b/top_k_freq_element.cpp
index 86d7cb4..343595f 100644
--- a/top_k_freq_element.cpp
+++ b/top_k_freq_element.cpp
@@ -10,7 +10,7 @@ public:
priority_queue<pair<int, int>> pqp;
for (auto it = um.begin(); it != um.end(); it++) {
pqp.push(make_pair(it->second, it->first));
- if (pqp.size() > (int)um.size() - k)
+ if (pqp.size() > um.size() - k)
ans.push_back(pqp.top().second), pqp.pop();
}
return ans;
diff --git a/uncrossed_lines.cpp b/uncrossed_lines.cpp
index 227faa9..c8156b1 100644
--- a/uncrossed_lines.cpp
+++ b/uncrossed_lines.cpp
@@ -16,7 +16,7 @@ class Solution {
public:
int maxUncrossedLines(vector<int> &nums1, vector<int> &nums2) {
int n = nums1.size(), m = nums2.size();
- vvd(int) dp(n + 1, vector<int>(m + 1, 0));
+ vvd dp(n + 1, vector<int>(m + 1, 0));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (nums1[i - 1] == nums2[j - 1])
diff --git a/unique_paths2.cpp b/unique_paths2.cpp
index 91a4201..fedb826 100644
--- a/unique_paths2.cpp
+++ b/unique_paths2.cpp
@@ -21,7 +21,7 @@ class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>> &obstacleGrid) {
int m = obstacleGrid.size(), n = obstacleGrid[0].size();
- vvd(int) dp(m + 1, vector<int>(n + 1, 0));
+ vvd dp(m + 1, vector<int>(n + 1, 0));
dp[0][1] = 1;
for (int i = 1; i <= m; ++i)
for (int j = 1; j <= n; ++j)
@@ -33,7 +33,7 @@ public:
int main() {
Solution obj;
- vvd(int) og1 = {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}}, og2 = {{0, 1}, {0, 0}};
+ vvd og1 = {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}}, og2 = {{0, 1}, {0, 0}};
printf("%d\n", obj.uniquePathsWithObstacles(og1)); // expect: 2
printf("%d\n", obj.uniquePathsWithObstacles(og2)); // expect: 1
}
diff --git a/unique_paths3.cpp b/unique_paths3.cpp
index 3e8eb86..37876fa 100644
--- a/unique_paths3.cpp
+++ b/unique_paths3.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- int uniquePathsIII(vvd(int) & grid) {
+ int uniquePathsIII(vvd & grid) {
auto i1 = 0, j1 = 0, t_steps = 0;
for (auto i = 0; i < grid.size(); ++i)
for (auto j = 0; j < grid[0].size(); ++j) {
@@ -15,7 +15,7 @@ public:
}
private:
- int dfs(vvd(int) & grid, int i, int j, int step, int t_step) {
+ int dfs(vvd & grid, int i, int j, int step, int t_step) {
if (i < 0 || j < 0 || i >= grid.size() || j >= grid[0].size() ||
grid[i][j] == -1)
return 0;
@@ -33,6 +33,6 @@ private:
int main() {
Solution obj;
- vvd(int) grid = {{1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 2, -1}};
+ vvd grid = {{1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 2, -1}};
cout << obj.uniquePathsIII(grid); // expect: 2
}
diff --git a/valid_arrangement_pairs.cpp b/valid_arrangement_pairs.cpp
index f1f8b20..0493141 100644
--- a/valid_arrangement_pairs.cpp
+++ b/valid_arrangement_pairs.cpp
@@ -53,11 +53,11 @@ public:
int main() {
Solution obj;
- vvd(int) p1 = {{5, 1}, {4, 5}, {11, 9}, {9, 4}},
+ vvd p1 = {{5, 1}, {4, 5}, {11, 9}, {9, 4}},
p2 = {{1, 3}, {3, 2}, {2, 1}}, p3 = {{1, 2}, {1, 3}, {2, 1}};
- vvd(int) va1 = obj.validArrangement(p1);
- vvd(int) va2 = obj.validArrangement(p2);
- vvd(int) va3 = obj.validArrangement(p3);
+ vvd va1 = obj.validArrangement(p1);
+ vvd va2 = obj.validArrangement(p2);
+ vvd va3 = obj.validArrangement(p3);
for (int i = 0; i < va1.size(); i++)
for (int j = 0; j < va1[0].size(); j++)
printf("%d ", va1[i][j]); // expect: [[11,9],[9,4],[4,5],[5,1]]
diff --git a/vertical_order_bst.cpp b/vertical_order_bst.cpp
index e8bf5bf..a429d4d 100644
--- a/vertical_order_bst.cpp
+++ b/vertical_order_bst.cpp
@@ -2,7 +2,7 @@
class Solution {
public:
- vvd(int) verticalTraversal(TreeNode *root) {
+ vvd verticalTraversal(TreeNode *root) {
map<int, map<int, multiset<int>>> mmm;
queue<pair<TreeNode *, pair<int, int>>> qpp;
qpp.push({root, {0, 0}});
@@ -17,7 +17,7 @@ public:
if (node->right)
qpp.push({node->right, {x + 1, y + 1}});
}
- vvd(int) ans;
+ vvd ans;
for (auto q : mmm) {
vector<int> col;
for (auto p : q.second)
diff --git a/where_will_ball_fall.cpp b/where_will_ball_fall.cpp
index ee859b7..4195778 100644
--- a/where_will_ball_fall.cpp
+++ b/where_will_ball_fall.cpp
@@ -2,9 +2,9 @@
class Solution {
public:
- vector<int> findBall(vvd(int) & grid) {
+ vector<int> findBall(vvd & grid) {
int m = grid.size(), n = grid[0].size();
- vvd(int) ugrid(m * 3, vector<int>(n * 3));
+ vvd ugrid(m * 3, vector<int>(n * 3));
for (auto i = 0; i < m; i++)
for (auto j = 0; j < n; j++) {
ugrid[i * 3 + 1][j * 3 + 1] = 1;
@@ -19,7 +19,7 @@ public:
private:
vector<pair<int, int>> dir{{1, 0}, {0, -1}, {0, 1}};
- int drop(int pos, vvd(int) & ugrid, int m, int n) {
+ int drop(int pos, vvd & ugrid, int m, int n) {
queue<pair<int, int>> qp;
qp.push({0, pos});
while (!qp.empty()) {
@@ -40,7 +40,7 @@ private:
int main() {
Solution obj;
- vvd(int) grid = {{1, 1, 1, -1, -1},
+ vvd grid = {{1, 1, 1, -1, -1},
{1, 1, 1, -1, -1},
{-1, -1, -1, 1, 1},
{1, 1, 1, 1, -1},
diff --git a/word_ladder2.cpp b/word_ladder2.cpp
index 7473ad2..12cff05 100644
--- a/word_ladder2.cpp
+++ b/word_ladder2.cpp
@@ -27,9 +27,9 @@ public:
continue;
if (um.find(t) == um.end())
continue;
- if (um[t] < (int)v.size())
+ if (um[t] < v.size())
continue;
- um[t] = (int)v.size();
+ um[t] = v.size();
v.push_back(t);
qpv.push({t, v});
v.pop_back();
diff --git a/zigzag_conversion.cpp b/zigzag_conversion.cpp
index aa3fba6..f7e6b74 100644
--- a/zigzag_conversion.cpp
+++ b/zigzag_conversion.cpp
@@ -16,7 +16,7 @@ public:
string convert(string s, int numRows) {
if (numRows <= 1)
return s;
- const int len = (int)s.size();
+ const int len = s.size();
string *str = new string[numRows];
int row = 0, step = 1;
for (int i = 0; i < len; ++i) {