diff --git a/README.md b/README.md index a96cea94..cf815b4e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![](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) > ["For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."](https://www.quora.com/How-effective-is-Leetcode-for-preparing-for-technical-interviews) -* [Programming Skills I](#programming-skills-i) * [Programming Skills II](#programming-skills-ii) * [Graph Theory I](#graph-theory-i) * [SQL I](#sql-i) @@ -16,102 +15,7 @@ * [Binary Search I](#binary-search-i) * [Binary Search II](#binary-search-ii) * [Dynamic Programming I](#dynamic-programming-i) - -### Programming Skills I - -#### Day 1 Basic Data Type - -| | | | | | -|-|-|-|-|-|- -| 1523 |[Count Odd Numbers in an Interval Range](src/main/kotlin/g1501_1600/s1523_count_odd_numbers_in_an_interval_range)| Easy | Math | 114 | 97.22 -| 1491 |[Average Salary Excluding the Minimum and Maximum Salary](src/main/kotlin/g1401_1500/s1491_average_salary_excluding_the_minimum_and_maximum_salary)| Easy | Array, Sorting | 165 | 27.87 - -#### Day 2 Operator - -| | | | | | -|-|-|-|-|-|- -| 0191 |[Number of 1 Bits](src/main/kotlin/g0101_0200/s0191_number_of_1_bits)| Easy | Top_Interview_Questions, Bit_Manipulation | 237 | 68.44 -| 1281 |[Subtract the Product and Sum of Digits of an Integer](src/main/kotlin/g1201_1300/s1281_subtract_the_product_and_sum_of_digits_of_an_integer)| Easy | Math | 128 | 61.82 - -#### Day 3 Conditional Statements - -| | | | | | -|-|-|-|-|-|- -| 0976 |[Largest Perimeter Triangle](src/main/kotlin/g0901_1000/s0976_largest_perimeter_triangle)| Easy | Array, Math, Sorting, Greedy | 304 | 33.33 -| 1779 |[Find Nearest Point That Has the Same X or Y Coordinate](src/main/kotlin/g1701_1800/s1779_find_nearest_point_that_has_the_same_x_or_y_coordinate)| Easy | Array | 364 | 100.00 - -#### Day 4 Loop - -| | | | | | -|-|-|-|-|-|- -| 1822 |[Sign of the Product of an Array](src/main/kotlin/g1801_1900/s1822_sign_of_the_product_of_an_array)| Easy | Array, Math | 170 | 92.51 -| 1502 |[Can Make Arithmetic Progression From Sequence](src/main/kotlin/g1501_1600/s1502_can_make_arithmetic_progression_from_sequence)| Easy | Array, Sorting | 156 | 94.82 -| 0202 |[Happy Number](src/main/kotlin/g0201_0300/s0202_happy_number)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 261 | 45.08 -| 1790 |[Check if One String Swap Can Make Strings Equal](src/main/kotlin/g1701_1800/s1790_check_if_one_string_swap_can_make_strings_equal)| Easy | String, Hash_Table, Counting | 138 | 100.00 - -#### Day 5 Function - -| | | | | | -|-|-|-|-|-|- -| 0589 |[N-ary Tree Preorder Traversal](src/main/kotlin/g0501_0600/s0589_n_ary_tree_preorder_traversal)| Easy | Depth_First_Search, Tree, Stack | 233 | 84.02 -| 0496 |[Next Greater Element I](src/main/kotlin/g0401_0500/s0496_next_greater_element_i)| Easy | Array, Hash_Table, Stack, Monotonic_Stack | 171 | 100.00 -| 1232 |[Check If It Is a Straight Line](src/main/kotlin/g1201_1300/s1232_check_if_it_is_a_straight_line)| Easy | Array, Math, Geometry | 152 | 95.38 - -#### Day 6 Array - -| | | | | | -|-|-|-|-|-|- -| 1588 |[Sum of All Odd Length Subarrays](src/main/kotlin/g1501_1600/s1588_sum_of_all_odd_length_subarrays)| Easy | Array, Math, Prefix_Sum | 157 | 64.00 -| 0283 |[Move Zeroes](src/main/kotlin/g0201_0300/s0283_move_zeroes)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 516 | 79.07 -| 1672 |[Richest Customer Wealth](src/main/kotlin/g1601_1700/s1672_richest_customer_wealth)| Easy | Array, Matrix | 155 | 94.54 - -#### Day 7 Array - -| | | | | | -|-|-|-|-|-|- -| 1572 |[Matrix Diagonal Sum](src/main/kotlin/g1501_1600/s1572_matrix_diagonal_sum)| Easy | Array, Matrix | 221 | 67.61 -| 0566 |[Reshape the Matrix](src/main/kotlin/g0501_0600/s0566_reshape_the_matrix)| Easy | Array, Matrix, Simulation | 239 | 99.05 - -#### Day 8 String - -| | | | | | -|-|-|-|-|-|- -| 1768 |[Merge Strings Alternately](src/main/kotlin/g1701_1800/s1768_merge_strings_alternately)| Easy | String, Two_Pointers | 138 | 93.81 -| 1678 |[Goal Parser Interpretation](src/main/kotlin/g1601_1700/s1678_goal_parser_interpretation)| Easy | String | 136 | 88.24 -| 0389 |[Find the Difference](src/main/kotlin/g0301_0400/s0389_find_the_difference)| Easy | String, Hash_Table, Sorting, Bit_Manipulation | 256 | 64.81 - -#### Day 9 String - -| | | | | | -|-|-|-|-|-|- -| 0709 |[To Lower Case](src/main/kotlin/g0701_0800/s0709_to_lower_case)| Easy | String | 142 | 98.68 -| 1309 |[Decrypt String from Alphabet to Integer Mapping](src/main/kotlin/g1301_1400/s1309_decrypt_string_from_alphabet_to_integer_mapping)| Easy | String | 129 | 95.45 -| 0953 |[Verifying an Alien Dictionary](src/main/kotlin/g0901_1000/s0953_verifying_an_alien_dictionary)| Easy | Array, String, Hash_Table | 137 | 100.00 - -#### Day 10 Linked List and Tree - -| | | | | | -|-|-|-|-|-|- -| 1290 |[Convert Binary Number in a Linked List to Integer](src/main/kotlin/g1201_1300/s1290_convert_binary_number_in_a_linked_list_to_integer)| Easy | Math, Linked_List | 145 | 25.93 -| 0876 |[Middle of the Linked List](src/main/kotlin/g0801_0900/s0876_middle_of_the_linked_list)| Easy | Two_Pointers, Linked_List | 136 | 76.52 -| 0104 |[Maximum Depth of Binary Tree](src/main/kotlin/g0101_0200/s0104_maximum_depth_of_binary_tree)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 166 | 83.53 -| 0404 |[Sum of Left Leaves](src/main/kotlin/g0401_0500/s0404_sum_of_left_leaves)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 173 | 86.05 - -#### Day 11 Containers and Libraries - -| | | | | | -|-|-|-|-|-|- -| 1356 |[Sort Integers by The Number of 1 Bits](src/main/kotlin/g1301_1400/s1356_sort_integers_by_the_number_of_1_bits)| Easy | Array, Sorting, Bit_Manipulation, Counting | 236 | 92.31 -| 0232 |[Implement Queue using Stacks](src/main/kotlin/g0201_0300/s0232_implement_queue_using_stacks)| Easy | Stack, Design, Queue | 258 | 70.86 -| 0242 |[Valid Anagram](src/main/kotlin/g0201_0300/s0242_valid_anagram)| Easy | String, Hash_Table, Sorting | 251 | 87.65 -| 0217 |[Contains Duplicate](src/main/kotlin/g0201_0300/s0217_contains_duplicate)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 719 | 73.49 - -#### Day 12 Class and Object - -| | | | | | -|-|-|-|-|-|- -| 1603 |[Design Parking System](src/main/kotlin/g1601_1700/s1603_design_parking_system)| Easy | Design, Simulation, Counting | 376 | 31.83 -| 0303 |[Range Sum Query - Immutable](src/main/kotlin/g0301_0400/s0303_range_sum_query_immutable)| Easy | Array, Design, Prefix_Sum | 472 | 63.64 +* [Programming Skills I](#programming-skills-i) ### Programming Skills II @@ -1812,6 +1716,102 @@ | 0343 |[Integer Break](src/main/kotlin/g0301_0400/s0343_integer_break)| Medium | Dynamic_Programming, Math | 218 | 63.89 | 0279 |[Perfect Squares](src/main/kotlin/g0201_0300/s0279_perfect_squares)| Medium | Dynamic_Programming, Math, Breadth_First_Search | 176 | 98.80 +### Programming Skills I + +#### Day 1 Basic Data Type + +| | | | | | +|-|-|-|-|-|- +| 1523 |[Count Odd Numbers in an Interval Range](src/main/kotlin/g1501_1600/s1523_count_odd_numbers_in_an_interval_range)| Easy | Math | 114 | 97.22 +| 1491 |[Average Salary Excluding the Minimum and Maximum Salary](src/main/kotlin/g1401_1500/s1491_average_salary_excluding_the_minimum_and_maximum_salary)| Easy | Array, Sorting | 165 | 27.87 + +#### Day 2 Operator + +| | | | | | +|-|-|-|-|-|- +| 0191 |[Number of 1 Bits](src/main/kotlin/g0101_0200/s0191_number_of_1_bits)| Easy | Top_Interview_Questions, Bit_Manipulation | 237 | 68.44 +| 1281 |[Subtract the Product and Sum of Digits of an Integer](src/main/kotlin/g1201_1300/s1281_subtract_the_product_and_sum_of_digits_of_an_integer)| Easy | Math | 128 | 61.82 + +#### Day 3 Conditional Statements + +| | | | | | +|-|-|-|-|-|- +| 0976 |[Largest Perimeter Triangle](src/main/kotlin/g0901_1000/s0976_largest_perimeter_triangle)| Easy | Array, Math, Sorting, Greedy | 304 | 33.33 +| 1779 |[Find Nearest Point That Has the Same X or Y Coordinate](src/main/kotlin/g1701_1800/s1779_find_nearest_point_that_has_the_same_x_or_y_coordinate)| Easy | Array | 364 | 100.00 + +#### Day 4 Loop + +| | | | | | +|-|-|-|-|-|- +| 1822 |[Sign of the Product of an Array](src/main/kotlin/g1801_1900/s1822_sign_of_the_product_of_an_array)| Easy | Array, Math | 170 | 92.51 +| 1502 |[Can Make Arithmetic Progression From Sequence](src/main/kotlin/g1501_1600/s1502_can_make_arithmetic_progression_from_sequence)| Easy | Array, Sorting | 156 | 94.82 +| 0202 |[Happy Number](src/main/kotlin/g0201_0300/s0202_happy_number)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 261 | 45.08 +| 1790 |[Check if One String Swap Can Make Strings Equal](src/main/kotlin/g1701_1800/s1790_check_if_one_string_swap_can_make_strings_equal)| Easy | String, Hash_Table, Counting | 138 | 100.00 + +#### Day 5 Function + +| | | | | | +|-|-|-|-|-|- +| 0589 |[N-ary Tree Preorder Traversal](src/main/kotlin/g0501_0600/s0589_n_ary_tree_preorder_traversal)| Easy | Depth_First_Search, Tree, Stack | 233 | 84.02 +| 0496 |[Next Greater Element I](src/main/kotlin/g0401_0500/s0496_next_greater_element_i)| Easy | Array, Hash_Table, Stack, Monotonic_Stack | 171 | 100.00 +| 1232 |[Check If It Is a Straight Line](src/main/kotlin/g1201_1300/s1232_check_if_it_is_a_straight_line)| Easy | Array, Math, Geometry | 152 | 95.38 + +#### Day 6 Array + +| | | | | | +|-|-|-|-|-|- +| 1588 |[Sum of All Odd Length Subarrays](src/main/kotlin/g1501_1600/s1588_sum_of_all_odd_length_subarrays)| Easy | Array, Math, Prefix_Sum | 157 | 64.00 +| 0283 |[Move Zeroes](src/main/kotlin/g0201_0300/s0283_move_zeroes)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 516 | 79.07 +| 1672 |[Richest Customer Wealth](src/main/kotlin/g1601_1700/s1672_richest_customer_wealth)| Easy | Array, Matrix | 155 | 94.54 + +#### Day 7 Array + +| | | | | | +|-|-|-|-|-|- +| 1572 |[Matrix Diagonal Sum](src/main/kotlin/g1501_1600/s1572_matrix_diagonal_sum)| Easy | Array, Matrix | 221 | 67.61 +| 0566 |[Reshape the Matrix](src/main/kotlin/g0501_0600/s0566_reshape_the_matrix)| Easy | Array, Matrix, Simulation | 239 | 99.05 + +#### Day 8 String + +| | | | | | +|-|-|-|-|-|- +| 1768 |[Merge Strings Alternately](src/main/kotlin/g1701_1800/s1768_merge_strings_alternately)| Easy | String, Two_Pointers | 138 | 93.81 +| 1678 |[Goal Parser Interpretation](src/main/kotlin/g1601_1700/s1678_goal_parser_interpretation)| Easy | String | 136 | 88.24 +| 0389 |[Find the Difference](src/main/kotlin/g0301_0400/s0389_find_the_difference)| Easy | String, Hash_Table, Sorting, Bit_Manipulation | 256 | 64.81 + +#### Day 9 String + +| | | | | | +|-|-|-|-|-|- +| 0709 |[To Lower Case](src/main/kotlin/g0701_0800/s0709_to_lower_case)| Easy | String | 142 | 98.68 +| 1309 |[Decrypt String from Alphabet to Integer Mapping](src/main/kotlin/g1301_1400/s1309_decrypt_string_from_alphabet_to_integer_mapping)| Easy | String | 129 | 95.45 +| 0953 |[Verifying an Alien Dictionary](src/main/kotlin/g0901_1000/s0953_verifying_an_alien_dictionary)| Easy | Array, String, Hash_Table | 137 | 100.00 + +#### Day 10 Linked List and Tree + +| | | | | | +|-|-|-|-|-|- +| 1290 |[Convert Binary Number in a Linked List to Integer](src/main/kotlin/g1201_1300/s1290_convert_binary_number_in_a_linked_list_to_integer)| Easy | Math, Linked_List | 145 | 25.93 +| 0876 |[Middle of the Linked List](src/main/kotlin/g0801_0900/s0876_middle_of_the_linked_list)| Easy | Two_Pointers, Linked_List | 136 | 76.52 +| 0104 |[Maximum Depth of Binary Tree](src/main/kotlin/g0101_0200/s0104_maximum_depth_of_binary_tree)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H) | 166 | 83.53 +| 0404 |[Sum of Left Leaves](src/main/kotlin/g0401_0500/s0404_sum_of_left_leaves)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 173 | 86.05 + +#### Day 11 Containers and Libraries + +| | | | | | +|-|-|-|-|-|- +| 1356 |[Sort Integers by The Number of 1 Bits](src/main/kotlin/g1301_1400/s1356_sort_integers_by_the_number_of_1_bits)| Easy | Array, Sorting, Bit_Manipulation, Counting | 236 | 92.31 +| 0232 |[Implement Queue using Stacks](src/main/kotlin/g0201_0300/s0232_implement_queue_using_stacks)| Easy | Stack, Design, Queue | 258 | 70.86 +| 0242 |[Valid Anagram](src/main/kotlin/g0201_0300/s0242_valid_anagram)| Easy | String, Hash_Table, Sorting | 251 | 87.65 +| 0217 |[Contains Duplicate](src/main/kotlin/g0201_0300/s0217_contains_duplicate)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting | 719 | 73.49 + +#### Day 12 Class and Object + +| | | | | | +|-|-|-|-|-|- +| 1603 |[Design Parking System](src/main/kotlin/g1601_1700/s1603_design_parking_system)| Easy | Design, Simulation, Counting | 376 | 31.83 +| 0303 |[Range Sum Query - Immutable](src/main/kotlin/g0301_0400/s0303_range_sum_query_immutable)| Easy | Array, Design, Prefix_Sum | 472 | 63.64 + ## Algorithms | # | Title | Difficulty | Tag | Time, ms | Time, % diff --git a/src/main/kotlin/g0901_1000/s0939_minimum_area_rectangle/readme.md b/src/main/kotlin/g0901_1000/s0939_minimum_area_rectangle/readme.md index eaf14e24..b0b13dfd 100644 --- a/src/main/kotlin/g0901_1000/s0939_minimum_area_rectangle/readme.md +++ b/src/main/kotlin/g0901_1000/s0939_minimum_area_rectangle/readme.md @@ -35,7 +35,6 @@ Return _the minimum area of a rectangle formed from these points, with sides par ## Solution ```kotlin -import java.util.Arrays import kotlin.math.abs class Solution { @@ -48,9 +47,7 @@ class Solution { map.putIfAbsent(p[0], HashSet()) map.getValue(p[0]).add(p[1]) } - Arrays.sort( - points - ) { a: IntArray, b: IntArray -> + points.sortWith { a: IntArray, b: IntArray -> if (a[0] == b[0]) Integer.compare( a[1], b[1] diff --git a/src/main/kotlin/g0901_1000/s0956_tallest_billboard/readme.md b/src/main/kotlin/g0901_1000/s0956_tallest_billboard/readme.md index e6536ad6..89e90bea 100644 --- a/src/main/kotlin/g0901_1000/s0956_tallest_billboard/readme.md +++ b/src/main/kotlin/g0901_1000/s0956_tallest_billboard/readme.md @@ -44,8 +44,6 @@ Return _the largest possible height of your billboard installation_. If you cann ## Solution ```kotlin -import java.util.Arrays - class Solution { fun tallestBillboard(rods: IntArray): Int { var maxDiff = 0 @@ -53,7 +51,7 @@ class Solution { maxDiff += rod } val dp = IntArray(maxDiff + 1) - Arrays.fill(dp, -1) + dp.fill(-1) dp[0] = 0 for (l in rods) { val dpOld = IntArray(maxDiff + 1) diff --git a/src/main/kotlin/g0901_1000/s0957_prison_cells_after_n_days/readme.md b/src/main/kotlin/g0901_1000/s0957_prison_cells_after_n_days/readme.md index 96124ec1..1c43d1be 100644 --- a/src/main/kotlin/g0901_1000/s0957_prison_cells_after_n_days/readme.md +++ b/src/main/kotlin/g0901_1000/s0957_prison_cells_after_n_days/readme.md @@ -57,8 +57,6 @@ Day 7: [0, 0, 1, 1, 0, 0, 0, 0] ## Solution ```kotlin -import java.util.Arrays - @Suppress("NAME_SHADOWING") class Solution { fun prisonAfterNDays(cells: IntArray, n: Int): IntArray { @@ -74,7 +72,7 @@ class Solution { day++ n-- val next = getNextDay(prev) - if (Arrays.equals(next, first)) { + if (next.contentEquals(first)) { period = day - 1 n %= period } diff --git a/src/main/kotlin/g1001_1100/s1024_video_stitching/readme.md b/src/main/kotlin/g1001_1100/s1024_video_stitching/readme.md index 7eed100b..91140fb1 100644 --- a/src/main/kotlin/g1001_1100/s1024_video_stitching/readme.md +++ b/src/main/kotlin/g1001_1100/s1024_video_stitching/readme.md @@ -54,11 +54,9 @@ Now we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 1 ## Solution ```kotlin -import java.util.Arrays - class Solution { fun videoStitching(clips: Array, time: Int): Int { - Arrays.sort(clips) { a: IntArray, b: IntArray -> + clips.sortWith { a: IntArray, b: IntArray -> if (a[0] == b[0] ) a[1] - b[1] else a[0] - b[0] } diff --git a/src/main/kotlin/g1001_1100/s1027_longest_arithmetic_subsequence/readme.md b/src/main/kotlin/g1001_1100/s1027_longest_arithmetic_subsequence/readme.md index 104ed748..7e9f0fa7 100644 --- a/src/main/kotlin/g1001_1100/s1027_longest_arithmetic_subsequence/readme.md +++ b/src/main/kotlin/g1001_1100/s1027_longest_arithmetic_subsequence/readme.md @@ -38,8 +38,6 @@ Given an array `nums` of integers, return _the length of the longest arithmetic ## Solution ```kotlin -import java.util.Arrays - class Solution { fun longestArithSeqLength(nums: IntArray): Int { val max = maxElement(nums) @@ -48,7 +46,7 @@ class Solution { val n = nums.size val dp = Array(n) { IntArray(2 * diff + 2) } for (d in dp) { - Arrays.fill(d, 1) + d.fill(1) } var ans = 0 for (i in 0 until n) { diff --git a/src/main/kotlin/g1001_1100/s1029_two_city_scheduling/readme.md b/src/main/kotlin/g1001_1100/s1029_two_city_scheduling/readme.md index cc22f8e7..250e2285 100644 --- a/src/main/kotlin/g1001_1100/s1029_two_city_scheduling/readme.md +++ b/src/main/kotlin/g1001_1100/s1029_two_city_scheduling/readme.md @@ -49,11 +49,9 @@ The total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interv ## Solution ```kotlin -import java.util.Arrays - class Solution { fun twoCitySchedCost(costs: Array): Int { - Arrays.sort(costs) { a: IntArray, b: IntArray -> + costs.sortWith { a: IntArray, b: IntArray -> a[0] - a[1] - (b[0] - b[1]) } var cost = 0 diff --git a/src/main/kotlin/g1001_1100/s1081_smallest_subsequence_of_distinct_characters/readme.md b/src/main/kotlin/g1001_1100/s1081_smallest_subsequence_of_distinct_characters/readme.md index 59b47146..9b05b620 100644 --- a/src/main/kotlin/g1001_1100/s1081_smallest_subsequence_of_distinct_characters/readme.md +++ b/src/main/kotlin/g1001_1100/s1081_smallest_subsequence_of_distinct_characters/readme.md @@ -29,7 +29,6 @@ Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ ## Solution ```kotlin -import java.util.Arrays import java.util.Deque import java.util.LinkedList @@ -39,7 +38,7 @@ class Solution { val stk: Deque = LinkedList() val freq = IntArray(26) val exist = BooleanArray(26) - Arrays.fill(exist, false) + exist.fill(false) for (ch in s.toCharArray()) { freq[ch.code - 'a'.code]++ } diff --git a/src/main/kotlin/g1201_1300/s1235_maximum_profit_in_job_scheduling/readme.md b/src/main/kotlin/g1201_1300/s1235_maximum_profit_in_job_scheduling/readme.md index ee7229d1..1e891e5c 100644 --- a/src/main/kotlin/g1201_1300/s1235_maximum_profit_in_job_scheduling/readme.md +++ b/src/main/kotlin/g1201_1300/s1235_maximum_profit_in_job_scheduling/readme.md @@ -48,8 +48,6 @@ If you choose a job that ends at time `X` you will be able to start another job ## Solution ```kotlin -import java.util.Arrays - class Solution { fun jobScheduling(startTime: IntArray, endTime: IntArray, profit: IntArray): Int { val n = startTime.size @@ -59,7 +57,7 @@ class Solution { time[i][1] = endTime[i] time[i][2] = profit[i] } - Arrays.sort(time, { a: IntArray, b: IntArray -> a[1].compareTo(b[1]) }) + time.sortWith { a: IntArray, b: IntArray -> a[1].compareTo(b[1]) } val maxP = Array(n) { IntArray(2) } var lastPos = -1 var currProfit: Int diff --git a/src/main/kotlin/g1301_1400/s1353_maximum_number_of_events_that_can_be_attended/readme.md b/src/main/kotlin/g1301_1400/s1353_maximum_number_of_events_that_can_be_attended/readme.md index cbd5c893..3b794d06 100644 --- a/src/main/kotlin/g1301_1400/s1353_maximum_number_of_events_that_can_be_attended/readme.md +++ b/src/main/kotlin/g1301_1400/s1353_maximum_number_of_events_that_can_be_attended/readme.md @@ -44,12 +44,11 @@ Attend the third event on day 3. ## Solution ```kotlin -import java.util.Arrays import java.util.PriorityQueue class Solution { fun maxEvents(events: Array): Int { - Arrays.sort(events) { a: IntArray, b: IntArray -> a[0] - b[0] } + events.sortWith { a: IntArray, b: IntArray -> a[0] - b[0] } var ans = 0 var i = 0 val pq = PriorityQueue() diff --git a/src/main/kotlin/g1301_1400/s1366_rank_teams_by_votes/readme.md b/src/main/kotlin/g1301_1400/s1366_rank_teams_by_votes/readme.md index d74c8d55..7cd1e90a 100644 --- a/src/main/kotlin/g1301_1400/s1366_rank_teams_by_votes/readme.md +++ b/src/main/kotlin/g1301_1400/s1366_rank_teams_by_votes/readme.md @@ -55,8 +55,6 @@ As most of the voters ranked C second, team C is the second team and team B is t ## Solution ```kotlin -import java.util.Arrays - class Solution { internal class Node(var c: Char) { var count = IntArray(26) @@ -72,9 +70,8 @@ class Solution { nodes[vote[i].code - 'A'.code]!!.count[i]++ } } - Arrays.sort( - nodes - ) { o1: Node?, o2: Node? -> + + nodes.sortWith sort@{ o1: Node?, o2: Node? -> for (i in 0..25) { if (o1!!.count[i] != o2!!.count[i]) { return@sort o2.count[i] - o1.count[i] diff --git a/src/main/kotlin/g1301_1400/s1383_maximum_performance_of_a_team/readme.md b/src/main/kotlin/g1301_1400/s1383_maximum_performance_of_a_team/readme.md index 2acec6a5..180d73a7 100644 --- a/src/main/kotlin/g1301_1400/s1383_maximum_performance_of_a_team/readme.md +++ b/src/main/kotlin/g1301_1400/s1383_maximum_performance_of_a_team/readme.md @@ -50,7 +50,6 @@ This is the same example as the first but k = 3. We can select engineer 1, engin ## Solution ```kotlin -import java.util.Arrays import java.util.PriorityQueue class Solution { @@ -60,7 +59,7 @@ class Solution { engineers[i][0] = speed[i] engineers[i][1] = efficiency[i] } - Arrays.sort(engineers) { engineer1: IntArray, engineer2: IntArray -> engineer2[1] - engineer1[1] } + engineers.sortWith { engineer1: IntArray, engineer2: IntArray -> engineer2[1] - engineer1[1] } var speedSum: Long = 0 var maximumPerformance: Long = 0 val minHeap = PriorityQueue() diff --git a/src/main/kotlin/g1301_1400/s1387_sort_integers_by_the_power_value/readme.md b/src/main/kotlin/g1301_1400/s1387_sort_integers_by_the_power_value/readme.md index 00fd7d05..d6306277 100644 --- a/src/main/kotlin/g1301_1400/s1387_sort_integers_by_the_power_value/readme.md +++ b/src/main/kotlin/g1301_1400/s1387_sort_integers_by_the_power_value/readme.md @@ -56,8 +56,6 @@ The fourth number in the sorted array is 7. ## Solution ```kotlin -import java.util.Arrays - class Solution { private lateinit var cacheMap: MutableMap @@ -69,7 +67,7 @@ class Solution { arr[i][0] = lo + i arr[i][1] = getStepCount(lo + i) } - Arrays.sort(arr) { a: IntArray, b: IntArray -> a[1].compareTo(b[1]) } + arr.sortWith { a: IntArray, b: IntArray -> a[1].compareTo(b[1]) } return arr[k - 1][0] } diff --git a/src/main/kotlin/g1401_1500/s1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/readme.md b/src/main/kotlin/g1401_1500/s1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/readme.md index 168dcf46..893f5361 100644 --- a/src/main/kotlin/g1401_1500/s1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/readme.md +++ b/src/main/kotlin/g1401_1500/s1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree/readme.md @@ -51,7 +51,6 @@ The edges 2, 3, 4, and 5 are only part of some MSTs, therefore they are consider ## Solution ```kotlin -import java.util.Arrays import java.util.LinkedList class Solution { @@ -73,7 +72,7 @@ class Solution { mst[i] = LinkedList() } val mstSet = BooleanArray(edges.size) - Arrays.sort(edges) { a: IntArray, b: IntArray -> + edges.sortWith { a: IntArray, b: IntArray -> Integer.compare( a[2], b[2] )