Skip to content

Commit ca1159e

Browse files
authored
Added tasks 3354-3357
1 parent 97a9abd commit ca1159e

File tree

387 files changed

+1484
-661
lines changed
  • src/main/kotlin
    • g0001_0100
    • g0101_0200
    • g0201_0300
    • g0301_0400
    • g0401_0500
    • g0501_0600
    • g0601_0700
    • g0701_0800
    • g0801_0900
    • g0901_1000
    • g1001_1100
    • g1101_1200
      • s1106_parsing_a_boolean_expression
      • s1123_lowest_common_ancestor_of_deepest_leaves
      • s1129_shortest_path_with_alternating_colors
      • s1145_binary_tree_coloring_game
      • s1155_number_of_dice_rolls_with_target_sum
      • s1175_prime_arrangements
      • s1189_maximum_number_of_balloons
      • s1192_critical_connections_in_a_network
    • g1201_1300
      • s1222_queens_that_can_attack_the_king
      • s1226_the_dining_philosophers
      • s1227_airplane_seat_assignment_probability
      • s1250_check_if_it_is_a_good_array
      • s1275_find_winner_on_a_tic_tac_toe_game
      • s1277_count_square_submatrices_with_all_ones
      • s1278_palindrome_partitioning_iii
      • s1286_iterator_for_combination
      • s1288_remove_covered_intervals
      • s1291_sequential_digits
      • s1292_maximum_side_length_of_a_square_with_sum_less_than_or_equal_to_threshold
      • s1298_maximum_candies_you_can_get_from_boxes
    • g1301_1400
      • s1311_get_watched_videos_by_your_friends
      • s1315_sum_of_nodes_with_even_valued_grandparent
      • s1320_minimum_distance_to_type_a_word_using_two_fingers
      • s1325_delete_leaves_with_a_given_value
      • s1330_reverse_subarray_to_maximize_array_value
      • s1332_remove_palindromic_subsequences
      • s1333_filter_restaurants_by_vegan_friendly_price_and_distance
      • s1348_tweet_counts_per_frequency
      • s1357_apply_discount_every_n_orders
      • s1360_number_of_days_between_two_dates
      • s1367_linked_list_in_binary_tree
      • s1368_minimum_cost_to_make_at_least_one_valid_path_in_a_grid
      • s1371_find_the_longest_substring_containing_vowels_in_even_counts
      • s1379_find_a_corresponding_node_of_a_binary_tree_in_a_clone_of_that_tree
      • s1388_pizza_with_3n_slices
      • s1391_check_if_there_is_a_valid_path_in_a_grid
      • s1397_find_all_good_strings
    • g1401_1500
      • s1401_circle_and_rectangle_overlapping
      • s1406_stone_game_iii
      • s1411_number_of_ways_to_paint_n_3_grid
      • s1419_minimum_number_of_frogs_croaking
      • s1439_find_the_kth_smallest_sum_of_a_matrix_with_sorted_rows
      • s1443_minimum_time_to_collect_all_apples_in_a_tree
      • s1444_number_of_ways_of_cutting_a_pizza
      • s1447_simplified_fractions
      • s1452_people_whose_list_of_favorite_companies_is_not_a_subset_of_another_list
      • s1453_maximum_number_of_darts_inside_of_a_circular_dartboard
      • s1462_course_schedule_iv
      • s1473_paint_house_iii
      • s1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree
      • s1499_max_value_of_equation
    • g1501_1600
      • s1503_last_moment_before_all_ants_fall_out_of_a_plank
      • s1519_number_of_nodes_in_the_sub_tree_with_the_same_label
      • s1523_count_odd_numbers_in_an_interval_range
      • s1530_number_of_good_leaf_nodes_pairs
      • s1531_string_compression_ii
      • s1568_minimum_number_of_days_to_disconnect_island
      • s1569_number_of_ways_to_reorder_array_to_get_same_bst
      • s1579_remove_max_number_of_edges_to_keep_graph_fully_traversable
      • s1583_count_unhappy_friends
      • s1584_min_cost_to_connect_all_points
      • s1591_strange_printer_ii
      • s1594_maximum_non_negative_product_in_a_matrix
      • s1595_minimum_cost_to_connect_two_groups_of_points
      • s1600_throne_inheritance
    • g1601_1700
      • s1610_maximum_number_of_visible_points
      • s1617_count_subtrees_with_max_distance_between_cities
      • s1622_fancy_sequence
      • s1626_best_team_with_no_conflicts
      • s1631_path_with_minimum_effort
      • s1632_rank_transform_of_a_matrix
      • s1639_number_of_ways_to_form_a_target_string_given_a_dictionary
      • s1649_create_sorted_array_through_instructions
    • g1701_1800
      • s1704_determine_if_string_halves_are_alike
      • s1719_number_of_ways_to_reconstruct_a_tree
      • s1754_largest_merge_of_two_strings
      • s1766_tree_of_coprimes
      • s1770_maximum_score_from_performing_multiplication_operations
      • s1790_check_if_one_string_swap_can_make_strings_equal
      • s1791_find_center_of_star_graph
      • s1799_maximize_score_after_n_operations
    • g1801_1900
      • s1801_number_of_orders_in_the_backlog
      • s1819_number_of_different_subsequences_gcds
      • s1825_finding_mk_average
      • s1830_minimum_number_of_operations_to_make_string_sorted
      • s1834_single_threaded_cpu
      • s1857_largest_color_value_in_a_directed_graph
      • s1863_sum_of_all_subset_xor_totals
      • s1871_jump_game_vii
      • s1883_minimum_skips_to_arrive_at_meeting_on_time
      • s1895_largest_magic_square
      • s1896_minimum_cost_to_change_the_final_value_of_expression
    • g1901_2000
      • s1904_the_number_of_full_rounds_you_have_played
      • s1931_painting_a_grid_with_three_different_colors
      • s1932_merge_bsts_to_create_single_bst
      • s1977_number_of_ways_to_separate_numbers
      • s1991_find_the_middle_index_in_array
    • g2001_2100
      • s2008_maximum_earnings_from_taxi
      • s2029_stone_game_ix
      • s2035_partition_array_into_two_arrays_to_minimize_sum_difference
      • s2039_the_time_when_the_network_becomes_idle
      • s2056_number_of_valid_move_combinations_on_chessboard
      • s2060_check_if_an_original_string_exists_given_two_encoded_strings
      • s2065_maximum_path_quality_of_a_graph
      • s2097_valid_arrangement_of_pairs
    • g2101_2200
      • s2102_sequentially_ordinal_rank_tracker
      • s2115_find_all_possible_recipes_from_given_supplies
      • s2119_a_number_after_a_double_reversal
      • s2124_check_if_all_as_appears_before_all_bs
      • s2132_stamping_the_grid
      • s2145_count_the_hidden_sequences
      • s2151_maximum_good_people_based_on_statements
      • s2162_minimum_cost_to_set_cooking_time
      • s2170_minimum_operations_to_make_the_array_alternating
      • s2172_maximum_and_sum_of_array
      • s2177_find_three_consecutive_integers_that_sum_to_a_given_number
      • s2178_maximum_split_of_positive_even_integers
      • s2183_count_array_pairs_divisible_by_k
      • s2187_minimum_time_to_complete_trips
      • s2197_replace_non_coprime_numbers_in_array
    • g2201_2300
      • s2232_minimize_result_by_adding_parentheses_to_expression
      • s2260_minimum_consecutive_cards_to_pick_up
      • s2264_largest_3_same_digit_number_in_string
      • s2267_check_if_there_is_a_valid_parentheses_string_path
      • s2273_find_resultant_array_after_removing_anagrams
      • s2281_sum_of_total_strength_of_wizards
      • s2286_booking_concert_tickets_in_groups
      • s2288_apply_discount_to_prices
    • g2301_2400
      • s2318_number_of_distinct_roll_sequences
      • s2322_minimum_score_after_removals_on_a_tree
      • s2349_design_a_number_container_system
      • s2353_design_a_food_rating_system
      • s2360_longest_cycle_in_a_graph
      • s2374_node_with_highest_edge_score
      • s2376_count_special_integers
      • s2383_minimum_hours_of_training_to_win_a_competition
      • s2398_maximum_number_of_robots_within_budget
    • g2401_2500
      • s2404_most_frequent_even_element
      • s2409_count_days_spent_together
      • s2435_paths_in_matrix_whose_sum_is_divisible_by_k
      • s2440_create_components_with_same_value
      • s2447_number_of_subarrays_with_gcd_equal_to_k
      • s2452_words_within_two_edits_of_dictionary
      • s2455_average_value_of_even_numbers_that_are_divisible_by_three
      • s2458_height_of_binary_tree_after_subtree_removal_queries
      • s2463_minimum_total_distance_traveled
      • s2467_most_profitable_path_in_a_tree
      • s2497_maximum_star_sum_of_a_graph
      • s2499_minimum_total_cost_to_make_arrays_unequal
    • g2501_2600
      • s2508_add_edges_to_make_degrees_of_all_nodes_even
      • s2512_reward_top_k_students
      • s2513_minimize_the_maximum_of_two_arrays
      • s2515_shortest_distance_to_target_string_in_a_circular_array
      • s2541_minimum_operations_to_make_array_equal_ii
      • s2551_put_marbles_in_bags
      • s2562_find_the_array_concatenation_value
      • s2564_substring_xor_queries
      • s2566_maximum_difference_by_remapping_a_digit
      • s2572_count_the_number_of_square_free_subsets
      • s2592_maximize_greatness_of_an_array
      • s2593_find_score_of_an_array_after_marking_all_elements
    • g2601_2700
      • s2616_minimize_the_maximum_difference_of_pairs
      • s2644_find_the_maximum_divisibility_score
      • s2646_minimize_the_total_price_of_the_trips
      • s2658_maximum_number_of_fish_in_a_grid
      • s2659_make_array_empty
      • s2680_maximum_or
      • s2685_count_the_number_of_complete_components
      • s2697_lexicographically_smallest_palindrome
      • s2698_find_the_punishment_number_of_an_integer
      • s2699_modify_graph_edge_weights
    • g2701_2800
      • s2719_count_of_integers
      • s2729_check_if_the_number_is_fascinating
      • s2736_maximum_sum_queries
      • s2746_decremental_string_concatenation
      • s2747_count_zero_request_servers
      • s2767_partition_string_into_minimum_beautiful_substrings
      • s2768_number_of_black_blocks
      • s2785_sort_vowels_in_a_string
      • s2799_count_complete_subarrays_in_an_array
      • s2800_shortest_string_that_contains_three_strings
    • g2801_2900
      • s2807_insert_greatest_common_divisors_in_linked_list
      • s2812_find_the_safest_path_in_a_grid
      • s2818_apply_operations_to_maximize_score
      • s2827_number_of_beautiful_integers_in_the_range
      • s2830_maximize_the_profit_as_the_salesman
      • s2846_minimum_edge_weight_equilibrium_queries_in_a_tree
      • s2850_minimum_moves_to_spread_stones_over_grid
      • s2861_maximum_number_of_alloys
      • s2865_beautiful_towers_i
      • s2872_maximum_number_of_k_divisible_components
      • s2873_maximum_value_of_an_ordered_triplet_i
      • s2876_count_visited_nodes_in_a_directed_graph
    • g2901_3000
      • s2910_minimum_number_of_groups_to_create_a_valid_assignment
      • s2919_minimum_increment_operations_to_make_array_beautiful
      • s2948_make_lexicographically_smallest_array_by_swapping_elements
      • s2954_count_the_number_of_infection_sequences
      • s2957_remove_adjacent_almost_equal_characters
      • s2968_apply_operations_to_maximize_frequency_score
      • s2975_maximum_square_area_by_removing_fences_from_a_field
      • s2976_minimum_cost_to_convert_string_i
      • s2977_minimum_cost_to_convert_string_ii
      • s2999_count_the_number_of_powerful_integers
    • g3001_3100
      • s3013_divide_an_array_into_subarrays_with_minimum_cost_ii
      • s3026_maximum_good_subarray_sum
      • s3030_find_the_grid_of_region_average
      • s3044_most_frequent_prime
      • s3076_shortest_uncommon_substring_in_an_array
      • s3077_maximum_strength_of_k_disjoint_subarrays
      • s3098_find_the_sum_of_subsequence_powers
    • g3101_3200
      • s3102_minimize_manhattan_distances
      • s3130_find_all_possible_stable_binary_arrays_ii
      • s3136_valid_word
      • s3149_find_the_minimum_cost_array_permutation
      • s3165_maximum_sum_of_subsequence_with_non_adjacent_elements
      • s3181_maximum_total_reward_using_operations_ii
      • s3186_maximum_total_damage_with_spell_casting
      • s3187_peaks_in_array
      • s3197_find_the_minimum_area_to_cover_all_ones_ii
    • g3201_3300
      • s3203_find_minimum_diameter_after_merging_two_trees
      • s3235_check_if_the_rectangle_corner_is_reachable
      • s3241_time_taken_to_mark_all_nodes
      • s3250_find_the_count_of_monotonic_pairs_i
      • s3266_final_array_state_after_k_multiplication_operations_ii
      • s3270_find_the_key_of_the_numbers
      • s3272_find_the_count_of_good_integers
      • s3283_maximum_number_of_moves_to_kill_all_pawns
      • s3288_length_of_the_longest_increasing_path
    • g3301_3400
      • s3311_construct_2d_grid_matching_graph_layout
      • s3318_find_x_sum_of_all_k_long_subarrays_i
      • s3343_count_number_of_balanced_permutations
      • s3349_adjacent_increasing_subarrays_detection_i
      • s3350_adjacent_increasing_subarrays_detection_ii
      • s3352_count_k_reducible_numbers_less_than_n
      • s3354_make_array_elements_equal_to_zero
      • s3355_zero_array_transformation_i
      • s3356_zero_array_transformation_ii
      • s3357_minimize_the_maximum_adjacent_element_difference

Some content is hidden

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

387 files changed

+1484
-661
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,10 @@
18161816

18171817
| # | Title | Difficulty | Tag | Time, ms | Time, %
18181818
|------|----------------|-------------|-------------|----------|--------
1819+
| 3357 |[Minimize the Maximum Adjacent Element Difference](src/main/kotlin/g3301_3400/s3357_minimize_the_maximum_adjacent_element_difference)| Hard | Array, Greedy, Binary_Search | 13 | 100.00
1820+
| 3356 |[Zero Array Transformation II](src/main/kotlin/g3301_3400/s3356_zero_array_transformation_ii)| Medium | Array, Binary_Search, Prefix_Sum | 5 | 100.00
1821+
| 3355 |[Zero Array Transformation I](src/main/kotlin/g3301_3400/s3355_zero_array_transformation_i)| Medium | Array, Prefix_Sum | 6 | 36.84
1822+
| 3354 |[Make Array Elements Equal to Zero](src/main/kotlin/g3301_3400/s3354_make_array_elements_equal_to_zero)| Easy | Array, Simulation, Prefix_Sum | 153 | 96.67
18191823
| 3352 |[Count K-Reducible Numbers Less Than N](src/main/kotlin/g3301_3400/s3352_count_k_reducible_numbers_less_than_n)| Hard | String, Dynamic_Programming, Math, Combinatorics | 170 | 100.00
18201824
| 3351 |[Sum of Good Subsequences](src/main/kotlin/g3301_3400/s3351_sum_of_good_subsequences)| Hard | Array, Hash_Table, Dynamic_Programming | 16 | 100.00
18211825
| 3350 |[Adjacent Increasing Subarrays Detection II](src/main/kotlin/g3301_3400/s3350_adjacent_increasing_subarrays_detection_ii)| Medium | Array, Binary_Search | 947 | 48.57

src/main/kotlin/g0001_0100/s0005_longest_palindromic_substring/readme.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ class Solution {
5353
var lpsCenter = 0
5454
var lpsRadius = 0
5555
for (i in newStr.indices) {
56-
dp[i] = if (friendCenter + friendRadius > i) Math.min(
57-
dp[friendCenter * 2 - i],
58-
friendCenter + friendRadius - i
59-
) else 1
56+
dp[i] = if (friendCenter + friendRadius > i) {
57+
Math.min(
58+
dp[friendCenter * 2 - i],
59+
friendCenter + friendRadius - i,
60+
)
61+
} else {
62+
1
63+
}
6064
while (i + dp[i] < newStr.size && i - dp[i] >= 0 && newStr[i + dp[i]] == newStr[i - dp[i]]) {
6165
dp[i]++
6266
}

src/main/kotlin/g0001_0100/s0010_regular_expression_matching/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Solution {
8989
i,
9090
j - 2,
9191
s,
92-
p
92+
p,
9393
)
9494
}
9595
} else {

src/main/kotlin/g0001_0100/s0017_letter_combinations_of_a_phone_number/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Solution {
5252
nums: String,
5353
letters: Array<String>,
5454
curr: StringBuilder,
55-
ans: MutableList<String>
55+
ans: MutableList<String>,
5656
) {
5757
if (curr.length == nums.length) {
5858
ans.add(curr.toString())

src/main/kotlin/g0001_0100/s0023_merge_k_sorted_lists/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ class Solution {
5656
fun mergeKLists(lists: Array<ListNode>): ListNode? {
5757
return if (lists.isEmpty()) {
5858
null
59-
} else mergeKLists(lists, 0, lists.size)
59+
} else {
60+
mergeKLists(lists, 0, lists.size)
61+
}
6062
}
6163

6264
private fun mergeKLists(lists: Array<ListNode>, leftIndex: Int, rightIndex: Int): ListNode? {

src/main/kotlin/g0001_0100/s0030_substring_with_concatenation_of_all_words/readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class Solution {
8686
// move a word's length each time
8787
var j = i
8888
while (j + window <= s.length) {
89-
9089
// get the subStr
9190
val subStr = s.substring(j, j + window)
9291
val map: MutableMap<String, Int> = HashMap()

src/main/kotlin/g0001_0100/s0040_combination_sum_ii/readme.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Solution {
4848
target: Int,
4949
start: Int,
5050
sums: MutableList<List<Int>>,
51-
sum: LinkedList<Int>
51+
sum: LinkedList<Int>,
5252
) {
5353
if (target == 0) {
5454
// make a deep copy of the current combination
@@ -57,7 +57,6 @@ class Solution {
5757
}
5858
var i = start
5959
while (i < candidates.size && target >= candidates[i]) {
60-
6160
// If candidate[i] equals candidate[i-1], then solutions for i is subset of
6261
// solution of i-1
6362
if (i == start || i > start && candidates[i] != candidates[i - 1]) {

src/main/kotlin/g0001_0100/s0046_permutations/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Solution {
4848
nums: IntArray,
4949
finalResult: MutableList<List<Int>>,
5050
currResult: MutableList<Int>,
51-
used: BooleanArray
51+
used: BooleanArray,
5252
) {
5353
if (currResult.size == nums.size) {
5454
finalResult.add(ArrayList(currResult))

src/main/kotlin/g0001_0100/s0048_rotate_image/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Solution {
4343
intArrayOf(i, j),
4444
intArrayOf(j, n - 1 - i),
4545
intArrayOf(n - 1 - i, n - 1 - j),
46-
intArrayOf(n - 1 - j, i)
46+
intArrayOf(n - 1 - j, i),
4747
)
4848
var t = matrix[pos[0][0]][pos[0][1]]
4949
for (k in 1 until pos.size) {

src/main/kotlin/g0001_0100/s0049_group_anagrams/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Solution {
4444
ch.sort()
4545
val temp = String(ch)
4646
hm.computeIfAbsent(
47-
temp
47+
temp,
4848
) { _: String? -> ArrayList() }
4949
hm.getValue(temp).add(s)
5050
}

src/main/kotlin/g0001_0100/s0050_powx_n/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class Solution {
5757
}
5858
return if (n < 0) {
5959
1.0 / res
60-
} else res
60+
} else {
61+
res
62+
}
6163
}
6264
}
6365
```

src/main/kotlin/g0001_0100/s0052_n_queens_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Solution {
4747
row: BooleanArray,
4848
col: BooleanArray,
4949
diagonal: BooleanArray,
50-
antiDiagonal: BooleanArray
50+
antiDiagonal: BooleanArray,
5151
): Int {
5252
if (r == n) {
5353
return 1

src/main/kotlin/g0001_0100/s0079_word_search/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Solution {
5353
word: String,
5454
index: Int,
5555
x: Int,
56-
y: Int
56+
y: Int,
5757
): Boolean {
5858
if (index == word.length) {
5959
return true
@@ -82,7 +82,7 @@ class Solution {
8282
fun exist(board: Array<CharArray>, word: String): Boolean {
8383
val visited = Array(board.size) {
8484
BooleanArray(
85-
board[0].size
85+
board[0].size,
8686
)
8787
}
8888
for (i in board.indices) {

src/main/kotlin/g0001_0100/s0084_largest_rectangle_in_histogram/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Solution {
7070
maxOfThreeNums(
7171
largestArea(a, start, minInd),
7272
a[minInd] * (limit - start),
73-
largestArea(a, minInd + 1, limit)
73+
largestArea(a, minInd + 1, limit),
7474
)
7575
}
7676
}

src/main/kotlin/g0001_0100/s0093_restore_ip_addresses/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Solution {
5252
'.' +
5353
octets[2] +
5454
'.' +
55-
octets[3]
55+
octets[3],
5656
)
5757
} else if (count < 4 && pos < 12) {
5858
var octet = 0

src/main/kotlin/g0001_0100/s0097_interleaving_string/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Solution {
6767
i1: Int,
6868
i2: Int,
6969
i3: Int,
70-
cache: Array<Array<Boolean?>>
70+
cache: Array<Array<Boolean?>>,
7171
): Boolean {
7272
if (cache[i1][i2] != null) {
7373
return cache[i1][i2]!!

src/main/kotlin/g0001_0100/s0098_validate_binary_search_tree/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class Solution {
6464
}
6565
return if (root.`val` <= left || root.`val` >= right) {
6666
false
67-
} else solve(root.left, left, root.`val`.toLong()) && solve(root.right, root.`val`.toLong(), right)
67+
} else {
68+
solve(root.left, left, root.`val`.toLong()) && solve(root.right, root.`val`.toLong(), right)
69+
}
6870
}
6971
}
7072
```

src/main/kotlin/g0001_0100/s0100_same_tree/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class Solution {
5858
return if (n != null && m != null) {
5959
if (n.`val` != m.`val`) {
6060
false
61-
} else trav(n.left, m.left) && trav(n.right, m.right)
61+
} else {
62+
trav(n.left, m.left) && trav(n.right, m.right)
63+
}
6264
} else {
6365
n == null && m == null
6466
}

src/main/kotlin/g0101_0200/s0101_symmetric_tree/readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class Solution {
4949
fun isSymmetric(root: TreeNode?): Boolean {
5050
return if (root == null) {
5151
true
52-
} else helper(root.left, root.right)
52+
} else {
53+
helper(root.left, root.right)
54+
}
5355
}
5456

5557
private fun helper(leftNode: TreeNode?, rightNode: TreeNode?): Boolean {
@@ -58,7 +60,9 @@ class Solution {
5860
}
5961
return if (leftNode.`val` != rightNode.`val`) {
6062
false
61-
} else helper(leftNode.left, rightNode.right) && helper(leftNode.right, rightNode.left)
63+
} else {
64+
helper(leftNode.left, rightNode.right) && helper(leftNode.right, rightNode.left)
65+
}
6266
}
6367
}
6468
```

src/main/kotlin/g0101_0200/s0112_path_sum/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class Solution {
7171
}
7272
return if (targetSum == root.`val` && root.left == null && root.right == null) {
7373
true
74-
} else hasPathSum(root.left, targetSum - root.`val`) || hasPathSum(root.right, targetSum - root.`val`)
74+
} else {
75+
hasPathSum(root.left, targetSum - root.`val`) || hasPathSum(root.right, targetSum - root.`val`)
76+
}
7577
}
7678
}
7779
```

src/main/kotlin/g0101_0200/s0113_path_sum_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Solution {
7474
al: ArrayList<Int>,
7575
sum: Int,
7676
targetSum: Int,
77-
root: TreeNode?
77+
root: TreeNode?,
7878
) {
7979
var sum = sum
8080
if (root == null) {

src/main/kotlin/g0101_0200/s0120_triangle/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Solution {
6868
triangle[row][col] +
6969
Math.min(
7070
dfs(triangle, dp, row + 1, col),
71-
dfs(triangle, dp, row + 1, col + 1)
71+
dfs(triangle, dp, row + 1, col + 1),
7272
)
7373
)
7474
dp[row][col] = sum

src/main/kotlin/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Find the maximum profit you can achieve. You may complete **at most two transact
4646
class Solution {
4747
fun maxProfit(prices: IntArray): Int {
4848
val n = prices.size
49-
if (n <2) {
49+
if (n < 2) {
5050
return 0
5151
}
5252
val a = IntArray(n) { 0 }

src/main/kotlin/g0101_0200/s0126_word_ladder_ii/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Solution {
7676
if (isLadder(word, next)) {
7777
// construct the reverse graph from endWord
7878
val reverseLadders = reverse.computeIfAbsent(
79-
next
79+
next,
8080
) { _: String? -> HashSet() }
8181
reverseLadders.add(word)
8282
if (endWord == next) {
@@ -115,7 +115,7 @@ class Solution {
115115
beginWord: String,
116116
graph: Map<String, MutableSet<String>>,
117117
ans: MutableList<List<String>>,
118-
path: MutableSet<String>
118+
path: MutableSet<String>,
119119
) {
120120
val next = graph[endWord] ?: return
121121
for (word in next) {

src/main/kotlin/g0101_0200/s0128_longest_consecutive_sequence/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Solution {
5050
if (num == lastNum) {
5151
continue
5252
}
53-
length ++
53+
length++
5454
if (num - lastNum > 1) {
5555
length = 1
5656
}

src/main/kotlin/g0101_0200/s0134_gas_station/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ class Solution {
8181
}
8282
return if (sumGas < sumCost) {
8383
-1
84-
} else result
84+
} else {
85+
result
86+
}
8587
}
8688
}
8789
```

src/main/kotlin/g0101_0200/s0140_word_break_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Solution {
5555
wordSet: Set<String>,
5656
index: Int,
5757
sb: StringBuilder,
58-
result: MutableList<String>
58+
result: MutableList<String>,
5959
) {
6060
if (index == s.length) {
6161
if (sb[sb.length - 1] == ' ') {

src/main/kotlin/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Solution {
6262
"/" to { a, b -> a / b },
6363
"*" to { a, b -> a * b },
6464
"+" to { a, b -> a + b },
65-
"-" to { a, b -> a - b }
65+
"-" to { a, b -> a - b },
6666
)
6767
fun evalRPN(tokens: Array<String>): Int {
6868
val stack = ArrayDeque<String>()

src/main/kotlin/g0101_0200/s0154_find_minimum_in_rotated_sorted_array_ii/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class Solution {
4444
fun findMin(nums: IntArray): Int {
4545
return if (nums.isEmpty()) {
4646
0
47-
} else find(0, nums.size - 1, nums)
47+
} else {
48+
find(0, nums.size - 1, nums)
49+
}
4850
}
4951

5052
private fun find(left: Int, right: Int, nums: IntArray): Int {

src/main/kotlin/g0101_0200/s0155_min_stack/readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ class MinStack() {
4848
private val stack: ArrayDeque<Pair<Int, Int>> = ArrayDeque()
4949

5050
fun push(x: Int) {
51-
val min: Int = if (stack.isEmpty()) x
52-
else getMin()
51+
val min: Int = if (stack.isEmpty()) {
52+
x
53+
} else {
54+
getMin()
55+
}
5356
stack.addLast(x to minOf(min, x))
5457
}
5558

src/main/kotlin/g0201_0300/s0201_bitwise_and_of_numbers_range/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Solution {
7070
-0x10,
7171
-0x8,
7272
-0x4,
73-
-0x2
73+
-0x2,
7474
)
7575
}
7676
}

src/main/kotlin/g0201_0300/s0210_course_schedule_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Solution {
7575
private fun buildGraph(
7676
numCourses: Int,
7777
prerequisites: Array<IntArray>,
78-
indegrees: IntArray
78+
indegrees: IntArray,
7979
): List<List<Int>> {
8080
val graph = List(numCourses) { mutableListOf<Int>() }
8181
for ((cur, prev) in prerequisites) {

src/main/kotlin/g0201_0300/s0222_count_complete_tree_nodes/readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ class Solution {
7070
private fun leftHeight(root: TreeNode?): Int {
7171
return if (root == null) {
7272
0
73-
} else 1 + leftHeight(root.left)
73+
} else {
74+
1 + leftHeight(root.left)
75+
}
7476
}
7577

7678
private fun rightHeight(root: TreeNode?): Int {
7779
return if (root == null) {
7880
0
79-
} else 1 + rightHeight(root.right)
81+
} else {
82+
1 + rightHeight(root.right)
83+
}
8084
}
8185
}
8286
```

src/main/kotlin/g0201_0300/s0258_add_digits/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Solution {
3737
}
3838
return if (num % 9 == 0) {
3939
9
40-
} else num % 9
40+
} else {
41+
num % 9
42+
}
4143
}
4244
}
4345
```

0 commit comments

Comments
 (0)