Skip to content

Commit bcd2e5d

Browse files
authored
Added tasks 1201-1606
1 parent be05987 commit bcd2e5d

File tree

197 files changed

+16580
-0
lines changed
  • src/main/kotlin
    • g1101_1200
    • g1201_1300
      • s1201_ugly_number_iii
      • s1202_smallest_string_with_swaps
      • s1203_sort_items_by_groups_respecting_dependencies
      • s1204_last_person_to_fit_in_the_bus
      • s1206_design_skiplist
      • s1207_unique_number_of_occurrences
      • s1208_get_equal_substrings_within_budget
      • s1209_remove_all_adjacent_duplicates_in_string_ii
      • s1210_minimum_moves_to_reach_target_with_rotations
      • s1211_queries_quality_and_percentage
      • s1217_minimum_cost_to_move_chips_to_the_same_position
      • s1218_longest_arithmetic_subsequence_of_given_difference
      • s1219_path_with_maximum_gold
      • s1220_count_vowels_permutation
      • s1221_split_a_string_in_balanced_strings
      • s1222_queens_that_can_attack_the_king
      • s1223_dice_roll_simulation
      • s1224_maximum_equal_frequency
      • s1226_the_dining_philosophers
      • s1227_airplane_seat_assignment_probability
      • s1232_check_if_it_is_a_straight_line
      • s1233_remove_sub_folders_from_the_filesystem
      • s1234_replace_the_substring_for_balanced_string
      • s1235_maximum_profit_in_job_scheduling
      • s1237_find_positive_integer_solution_for_a_given_equation
      • s1238_circular_permutation_in_binary_representation
      • s1239_maximum_length_of_a_concatenated_string_with_unique_characters
      • s1240_tiling_a_rectangle_with_the_fewest_squares
      • s1247_minimum_swaps_to_make_strings_equal
      • s1248_count_number_of_nice_subarrays
      • s1249_minimum_remove_to_make_valid_parentheses
      • s1250_check_if_it_is_a_good_array
      • s1251_average_selling_price
      • s1252_cells_with_odd_values_in_a_matrix
      • s1253_reconstruct_a_2_row_binary_matrix
      • s1254_number_of_closed_islands
      • s1255_maximum_score_words_formed_by_letters
      • s1260_shift_2d_grid
      • s1261_find_elements_in_a_contaminated_binary_tree
      • s1262_greatest_sum_divisible_by_three
      • s1263_minimum_moves_to_move_a_box_to_their_target_location
      • s1266_minimum_time_visiting_all_points
      • s1267_count_servers_that_communicate
      • s1268_search_suggestions_system
      • s1269_number_of_ways_to_stay_in_the_same_place_after_some_steps
      • s1275_find_winner_on_a_tic_tac_toe_game
      • s1276_number_of_burgers_with_no_waste_of_ingredients
      • s1277_count_square_submatrices_with_all_ones
      • s1278_palindrome_partitioning_iii
      • s1280_students_and_examinations
      • s1281_subtract_the_product_and_sum_of_digits_of_an_integer
      • s1282_group_the_people_given_the_group_size_they_belong_to
      • s1283_find_the_smallest_divisor_given_a_threshold
      • s1284_minimum_number_of_flips_to_convert_binary_matrix_to_zero_matrix
      • s1286_iterator_for_combination
      • s1287_element_appearing_more_than_25_in_sorted_array
      • s1288_remove_covered_intervals
      • s1289_minimum_falling_path_sum_ii
      • s1290_convert_binary_number_in_a_linked_list_to_integer
      • s1291_sequential_digits
      • s1292_maximum_side_length_of_a_square_with_sum_less_than_or_equal_to_threshold
      • s1293_shortest_path_in_a_grid_with_obstacles_elimination
      • s1295_find_numbers_with_even_number_of_digits
      • s1296_divide_array_in_sets_of_k_consecutive_numbers
      • s1297_maximum_number_of_occurrences_of_a_substring
      • s1298_maximum_candies_you_can_get_from_boxes
      • s1299_replace_elements_with_greatest_element_on_right_side
      • s1300_sum_of_mutated_array_closest_to_target
    • g1301_1400
    • g1401_1500
      • s1451_rearrange_words_in_a_sentence
      • s1452_people_whose_list_of_favorite_companies_is_not_a_subset_of_another_list
      • s1453_maximum_number_of_darts_inside_of_a_circular_dartboard
      • s1455_check_if_a_word_occurs_as_a_prefix_of_any_word_in_a_sentence
      • s1456_maximum_number_of_vowels_in_a_substring_of_given_length
      • s1457_pseudo_palindromic_paths_in_a_binary_tree
      • s1458_max_dot_product_of_two_subsequences
      • s1460_make_two_arrays_equal_by_reversing_subarrays
      • s1461_check_if_a_string_contains_all_binary_codes_of_size_k
      • s1462_course_schedule_iv
      • s1463_cherry_pickup_ii
      • s1464_maximum_product_of_two_elements_in_an_array
      • s1465_maximum_area_of_a_piece_of_cake_after_horizontal_and_vertical_cuts
      • s1466_reorder_routes_to_make_all_paths_lead_to_the_city_zero
      • s1467_probability_of_a_two_boxes_having_the_same_number_of_distinct_balls
      • s1470_shuffle_the_array
      • s1471_the_k_strongest_values_in_an_array
      • s1472_design_browser_history
      • s1473_paint_house_iii
      • s1475_final_prices_with_a_special_discount_in_a_shop
      • s1476_subrectangle_queries
      • s1477_find_two_non_overlapping_sub_arrays_each_with_target_sum
      • s1478_allocate_mailboxes
      • s1480_running_sum_of_1d_array
      • s1481_least_number_of_unique_integers_after_k_removals
      • s1482_minimum_number_of_days_to_make_m_bouquets
      • s1483_kth_ancestor_of_a_tree_node
      • s1484_group_sold_products_by_the_date
      • s1486_xor_operation_in_an_array
      • s1487_making_file_names_unique
      • s1488_avoid_flood_in_the_city
      • s1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree
      • s1491_average_salary_excluding_the_minimum_and_maximum_salary
      • s1492_the_kth_factor_of_n
      • s1493_longest_subarray_of_1s_after_deleting_one_element
      • s1494_parallel_courses_ii
      • s1496_path_crossing
      • s1497_check_if_array_pairs_are_divisible_by_k
      • s1498_number_of_subsequences_that_satisfy_the_given_sum_condition
      • s1499_max_value_of_equation
    • g1501_1600
      • s1502_can_make_arithmetic_progression_from_sequence
      • s1503_last_moment_before_all_ants_fall_out_of_a_plank
      • s1504_count_submatrices_with_all_ones
      • s1505_minimum_possible_integer_after_at_most_k_adjacent_swaps_on_digits
      • s1507_reformat_date
      • s1508_range_sum_of_sorted_subarray_sums
      • s1509_minimum_difference_between_largest_and_smallest_value_in_three_moves
      • s1510_stone_game_iv
      • s1512_number_of_good_pairs
      • s1513_number_of_substrings_with_only_1s
      • s1514_path_with_maximum_probability
      • s1515_best_position_for_a_service_centre
      • s1518_water_bottles
      • s1519_number_of_nodes_in_the_sub_tree_with_the_same_label
      • s1520_maximum_number_of_non_overlapping_substrings
      • s1521_find_a_value_of_a_mysterious_function_closest_to_target
      • s1523_count_odd_numbers_in_an_interval_range
      • s1524_number_of_sub_arrays_with_odd_sum
      • s1525_number_of_good_ways_to_split_a_string
      • s1526_minimum_number_of_increments_on_subarrays_to_form_a_target_array
      • s1527_patients_with_a_condition
      • s1528_shuffle_string
      • s1529_minimum_suffix_flips
      • s1530_number_of_good_leaf_nodes_pairs
      • s1531_string_compression_ii
      • s1534_count_good_triplets
      • s1535_find_the_winner_of_an_array_game
      • s1536_minimum_swaps_to_arrange_a_binary_grid
      • s1537_get_the_maximum_score
      • s1539_kth_missing_positive_number
      • s1540_can_convert_string_in_k_moves
      • s1541_minimum_insertions_to_balance_a_parentheses_string
      • s1542_find_longest_awesome_substring
      • s1544_make_the_string_great
      • s1545_find_kth_bit_in_nth_binary_string
      • s1546_maximum_number_of_non_overlapping_subarrays_with_sum_equals_target
      • s1547_minimum_cost_to_cut_a_stick
      • s1550_three_consecutive_odds
      • s1551_minimum_operations_to_make_array_equal
      • s1552_magnetic_force_between_two_balls
      • s1553_minimum_number_of_days_to_eat_n_oranges
      • s1556_thousand_separator
      • s1557_minimum_number_of_vertices_to_reach_all_nodes
      • s1558_minimum_numbers_of_function_calls_to_make_target_array
      • s1559_detect_cycles_in_2d_grid
      • s1560_most_visited_sector_in_a_circular_track
      • s1561_maximum_number_of_coins_you_can_get
      • s1562_find_latest_group_of_size_m
      • s1563_stone_game_v
      • s1566_detect_pattern_of_length_m_repeated_k_or_more_times
      • s1567_maximum_length_of_subarray_with_positive_product
      • s1568_minimum_number_of_days_to_disconnect_island
      • s1569_number_of_ways_to_reorder_array_to_get_same_bst
      • s1572_matrix_diagonal_sum
      • s1573_number_of_ways_to_split_a_string
      • s1574_shortest_subarray_to_be_removed_to_make_array_sorted
      • s1575_count_all_possible_routes
      • s1576_replace_all_s_to_avoid_consecutive_repeating_characters
      • s1577_number_of_ways_where_square_of_number_is_equal_to_product_of_two_numbers
      • s1578_minimum_time_to_make_rope_colorful
      • s1579_remove_max_number_of_edges_to_keep_graph_fully_traversable
      • s1581_customer_who_visited_but_did_not_make_any_transactions
      • s1582_special_positions_in_a_binary_matrix
      • s1583_count_unhappy_friends
      • s1584_min_cost_to_connect_all_points
      • s1585_check_if_string_is_transformable_with_substring_sort_operations
      • s1587_bank_account_summary_ii
      • s1588_sum_of_all_odd_length_subarrays
      • s1589_maximum_sum_obtained_of_any_permutation
      • s1590_make_sum_divisible_by_p
      • s1591_strange_printer_ii
      • s1592_rearrange_spaces_between_words
      • s1593_split_a_string_into_the_max_number_of_unique_substrings
      • s1594_maximum_non_negative_product_in_a_matrix
      • s1595_minimum_cost_to_connect_two_groups_of_points
      • s1598_crawler_log_folder
      • s1599_maximum_profit_of_operating_a_centennial_wheel
      • s1600_throne_inheritance
    • g1601_1700
      • s1601_maximum_number_of_achievable_transfer_requests
      • s1603_design_parking_system
      • s1604_alert_using_same_key_card_three_or_more_times_in_a_one_hour_period
      • s1605_find_valid_matrix_given_row_and_column_sums
      • s1606_find_servers_that_handled_most_number_of_requests

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+16580
-0
lines changed

README.md

Lines changed: 230 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 1174\. Immediate Food Delivery II
5+
6+
Medium
7+
8+
SQL Schema
9+
10+
Table: `Delivery`
11+
12+
+-----------------------------+---------+
13+
| Column Name | Type |
14+
+-----------------------------+---------+
15+
| delivery_id | int |
16+
| customer_id | int |
17+
| order_date | date |
18+
| customer_pref_delivery_date | date |
19+
+-----------------------------+---------+
20+
21+
delivery_id is the primary key of this table. The table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).
22+
23+
If the customer's preferred delivery date is the same as the order date, then the order is called **immediate;** otherwise, it is called **scheduled**.
24+
25+
The **first order** of a customer is the order with the earliest order date that the customer made. It is guaranteed that a customer has precisely one first order.
26+
27+
Write an SQL query to find the percentage of immediate orders in the first orders of all customers, **rounded to 2 decimal places**.
28+
29+
The query result format is in the following example.
30+
31+
**Example 1:**
32+
33+
**Input:** Delivery table:
34+
35+
+-------------+-------------+------------+-----------------------------+
36+
| delivery_id | customer_id | order_date | customer_pref_delivery_date |
37+
+-------------+-------------+------------+-----------------------------+
38+
| 1 | 1 | 2019-08-01 | 2019-08-02 |
39+
| 2 | 2 | 2019-08-02 | 2019-08-02 |
40+
| 3 | 1 | 2019-08-11 | 2019-08-12 |
41+
| 4 | 3 | 2019-08-24 | 2019-08-24 |
42+
| 5 | 3 | 2019-08-21 | 2019-08-22 |
43+
| 6 | 2 | 2019-08-11 | 2019-08-13 |
44+
| 7 | 4 | 2019-08-09 | 2019-08-09 |
45+
+-------------+-------------+------------+-----------------------------+
46+
47+
**Output:**
48+
49+
+----------------------+
50+
| immediate_percentage |
51+
+----------------------+
52+
| 50.00 |
53+
+----------------------+
54+
55+
**Explanation:** The customer id 1 has a first order with delivery id 1 and it is scheduled. The customer id 2 has a first order with delivery id 2 and it is immediate. The customer id 3 has a first order with delivery id 5 and it is scheduled. The customer id 4 has a first order with delivery id 7 and it is immediate. Hence, half the customers have immediate first orders.
56+
57+
## Solution
58+
59+
```sql
60+
# Write your MySQL query statement below
61+
SELECT ROUND(AVG(CASE WHEN customer_pref_delivery_date = order_date THEN 1 ELSE 0 END) * 100, 2) AS immediate_percentage
62+
FROM (
63+
SELECT *,
64+
DENSE_RANK() OVER(PARTITION BY customer_id ORDER BY order_date ASC) AS dnsrnk
65+
FROM delivery
66+
) subquery_alias
67+
WHERE subquery_alias.dnsrnk = 1;
68+
```
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 1193\. Monthly Transactions I
5+
6+
Medium
7+
8+
SQL Schema
9+
10+
Table: `Transactions`
11+
12+
+---------------+---------+
13+
| Column Name | Type |
14+
+---------------+---------+
15+
| id | int |
16+
| country | varchar |
17+
| state | enum |
18+
| amount | int |
19+
| trans_date | date |
20+
+---------------+---------+
21+
22+
id is the primary key of this table.
23+
24+
The table has information about incoming transactions.
25+
26+
The state column is an enum of type ["approved", "declined"].
27+
28+
Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.
29+
30+
Return the result table in **any order**.
31+
32+
The query result format is in the following example.
33+
34+
**Example 1:**
35+
36+
**Input:** Transactions table:
37+
38+
+------+---------+----------+--------+------------+
39+
| id | country | state | amount | trans_date |
40+
+------+---------+----------+--------+------------+
41+
| 121 | US | approved | 1000 | 2018-12-18 |
42+
| 122 | US | declined | 2000 | 2018-12-19 |
43+
| 123 | US | approved | 2000 | 2019-01-01 |
44+
| 124 | DE | approved | 2000 | 2019-01-07 |
45+
+------+---------+----------+--------+------------+
46+
47+
**Output:**
48+
49+
+----------+---------+-------------+----------------+--------------------+-----------------------+
50+
| month | country | trans_count | approved_count | trans_total_amount | approved_total_amount |
51+
+----------+---------+-------------+----------------+--------------------+-----------------------+
52+
| 2018-12 | US | 2 | 1 | 3000 | 1000 |
53+
| 2019-01 | US | 1 | 1 | 2000 | 2000 |
54+
| 2019-01 | DE | 1 | 1 | 2000 | 2000 |
55+
+----------+---------+-------------+----------------+--------------------+-----------------------+
56+
57+
## Solution
58+
59+
```sql
60+
# Write your MySQL query statement below
61+
SELECT
62+
FORMATDATETIME(trans_date, 'yyyy-MM') AS trans_month,
63+
country,
64+
COUNT(*) AS trans_count,
65+
SUM(CASE WHEN state = 'approved' THEN 1 ELSE 0 END) AS approved_count,
66+
SUM(amount) AS trans_total_amount,
67+
SUM(CASE WHEN state = 'approved' THEN amount ELSE 0 END) AS approved_total_amount
68+
FROM Transactions
69+
GROUP BY trans_month, country;
70+
```
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 1201\. Ugly Number III
5+
6+
Medium
7+
8+
An **ugly number** is a positive integer that is divisible by `a`, `b`, or `c`.
9+
10+
Given four integers `n`, `a`, `b`, and `c`, return the <code>n<sup>th</sup></code> **ugly number**.
11+
12+
**Example 1:**
13+
14+
**Input:** n = 3, a = 2, b = 3, c = 5
15+
16+
**Output:** 4
17+
18+
**Explanation:** The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3<sup>rd</sup> is 4.
19+
20+
**Example 2:**
21+
22+
**Input:** n = 4, a = 2, b = 3, c = 4
23+
24+
**Output:** 6
25+
26+
**Explanation:** The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4<sup>th</sup> is 6.
27+
28+
**Example 3:**
29+
30+
**Input:** n = 5, a = 2, b = 11, c = 13
31+
32+
**Output:** 10
33+
34+
**Explanation:** The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5<sup>th</sup> is 10.
35+
36+
**Constraints:**
37+
38+
* <code>1 <= n, a, b, c <= 10<sup>9</sup></code>
39+
* <code>1 <= a * b * c <= 10<sup>18</sup></code>
40+
* It is guaranteed that the result will be in range <code>[1, 2 * 10<sup>9</sup>]</code>.
41+
42+
## Solution
43+
44+
```kotlin
45+
class Solution {
46+
private fun getLcm(a: Long, b: Long): Long {
47+
var mx = a
48+
var mn = b
49+
if (a < b) {
50+
mx = b
51+
mn = a
52+
}
53+
while (mn != 0L) {
54+
val tmp = mn
55+
mn = mx % mn
56+
mx = tmp
57+
}
58+
return a * b / mx
59+
}
60+
61+
fun nthUglyNumber(n: Int, a: Int, b: Int, c: Int): Int {
62+
val ab = getLcm(a.toLong(), b.toLong())
63+
val ac = getLcm(a.toLong(), c.toLong())
64+
val bc = getLcm(b.toLong(), c.toLong())
65+
val abc = getLcm(a.toLong(), bc)
66+
var left: Long = 1
67+
var right: Long = 2000000001
68+
if (a != 0 && b != 0 && c != 0 && bc != 0L) {
69+
while (left < right) {
70+
val mid = left + (right - left) / 2
71+
if (mid / a + mid / b + mid / c - mid / ab - mid / ac - mid / bc + mid / abc >= n) {
72+
right = mid
73+
} else {
74+
left = mid + 1
75+
}
76+
}
77+
}
78+
return left.toInt()
79+
}
80+
}
81+
```
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 1202\. Smallest String With Swaps
5+
6+
Medium
7+
8+
You are given a string `s`, and an array of pairs of indices in the string `pairs` where `pairs[i] = [a, b]` indicates 2 indices(0-indexed) of the string.
9+
10+
You can swap the characters at any pair of indices in the given `pairs` **any number of times**.
11+
12+
Return the lexicographically smallest string that `s` can be changed to after using the swaps.
13+
14+
**Example 1:**
15+
16+
**Input:** s = "dcab", pairs = \[\[0,3],[1,2]]
17+
18+
**Output:** "bacd" **Explaination:**
19+
20+
Swap s[0] and s[3], s = "bcad"
21+
22+
Swap s[1] and s[2], s = "bacd"
23+
24+
**Example 2:**
25+
26+
**Input:** s = "dcab", pairs = \[\[0,3],[1,2],[0,2]]
27+
28+
**Output:** "abcd" **Explaination:**
29+
30+
Swap s[0] and s[3], s = "bcad"
31+
32+
Swap s[0] and s[2], s = "acbd"
33+
34+
Swap s[1] and s[2], s = "abcd"
35+
36+
**Example 3:**
37+
38+
**Input:** s = "cba", pairs = \[\[0,1],[1,2]]
39+
40+
**Output:** "abc" **Explaination:**
41+
42+
Swap s[0] and s[1], s = "bca"
43+
44+
Swap s[1] and s[2], s = "bac"
45+
46+
Swap s[0] and s[1], s = "abc"
47+
48+
**Constraints:**
49+
50+
* `1 <= s.length <= 10^5`
51+
* `0 <= pairs.length <= 10^5`
52+
* `0 <= pairs[i][0], pairs[i][1] < s.length`
53+
* `s` only contains lower case English letters.
54+
55+
## Solution
56+
57+
```kotlin
58+
class Solution {
59+
fun smallestStringWithSwaps(s: String, pairs: List<List<Int>>): String {
60+
val uf = UF(s.length)
61+
for (p in pairs) {
62+
uf.union(p[0], p[1])
63+
}
64+
val freqMapPerRoot: MutableMap<Int, IntArray> = HashMap()
65+
for (i in s.indices) {
66+
freqMapPerRoot.computeIfAbsent(uf.find(i)) { IntArray(26) }[s[i].code - 'a'.code]++
67+
}
68+
val ans = CharArray(s.length)
69+
for (i in ans.indices) {
70+
val css = freqMapPerRoot[uf.find(i)]
71+
for (j in css!!.indices) {
72+
if (css[j] > 0) {
73+
ans[i] = (j + 'a'.code).toChar()
74+
css[j]--
75+
break
76+
}
77+
}
78+
}
79+
return String(ans)
80+
}
81+
82+
internal class UF(n: Int) {
83+
var root: IntArray
84+
var rank: IntArray
85+
86+
init {
87+
root = IntArray(n)
88+
rank = IntArray(n)
89+
for (i in 0 until n) {
90+
root[i] = i
91+
rank[i] = 1
92+
}
93+
}
94+
95+
fun find(u: Int): Int {
96+
if (u == root[u]) {
97+
return u
98+
}
99+
root[u] = find(root[u])
100+
return root[u]
101+
}
102+
103+
fun union(u: Int, v: Int) {
104+
val ru = find(root[u])
105+
val rv = find(root[v])
106+
if (ru != rv) {
107+
if (rank[ru] < rank[rv]) {
108+
root[ru] = root[rv]
109+
} else if (rank[ru] > rank[rv]) {
110+
root[rv] = root[ru]
111+
} else {
112+
root[rv] = root[ru]
113+
rank[ru]++
114+
}
115+
}
116+
}
117+
}
118+
}
119+
```

0 commit comments

Comments
 (0)