File tree Expand file tree Collapse file tree 13 files changed +14
-38
lines changed
s0939_minimum_area_rectangle
s0957_prison_cells_after_n_days
s1027_longest_arithmetic_subsequence
s1029_two_city_scheduling
s1081_smallest_subsequence_of_distinct_characters
g1201_1300/s1235_maximum_profit_in_job_scheduling
s1353_maximum_number_of_events_that_can_be_attended
s1366_rank_teams_by_votes
s1383_maximum_performance_of_a_team
s1387_sort_integers_by_the_power_value
g1401_1500/s1489_find_critical_and_pseudo_critical_edges_in_minimum_spanning_tree Expand file tree Collapse file tree 13 files changed +14
-38
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package g0901_1000.s0939_minimum_area_rectangle
33// #Medium #Array #Hash_Table #Math #Sorting #Geometry
44// #2023_04_29_Time_461_ms_(100.00%)_Space_74.8_MB_(20.00%)
55
6- import java.util.Arrays
76import kotlin.math.abs
87
98class Solution {
@@ -16,9 +15,7 @@ class Solution {
1615 map.putIfAbsent(p[0 ], HashSet ())
1716 map.getValue(p[0 ]).add(p[1 ])
1817 }
19- Arrays .sort(
20- points
21- ) { a: IntArray , b: IntArray ->
18+ points.sortWith { a: IntArray , b: IntArray ->
2219 if (a[0 ] == b[0 ]) Integer .compare(
2320 a[1 ],
2421 b[1 ]
Original file line number Diff line number Diff line change @@ -2,16 +2,14 @@ package g0901_1000.s0956_tallest_billboard
22
33// #Hard #Array #Dynamic_Programming #2023_05_03_Time_182_ms_(100.00%)_Space_49.8_MB_(100.00%)
44
5- import java.util.Arrays
6-
75class Solution {
86 fun tallestBillboard (rods : IntArray ): Int {
97 var maxDiff = 0
108 for (rod in rods) {
119 maxDiff + = rod
1210 }
1311 val dp = IntArray (maxDiff + 1 )
14- Arrays .fill(dp, - 1 )
12+ dp .fill(- 1 )
1513 dp[0 ] = 0
1614 for (l in rods) {
1715 val dpOld = IntArray (maxDiff + 1 )
Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ package g0901_1000.s0957_prison_cells_after_n_days
33// #Medium #Array #Hash_Table #Math #Bit_Manipulation
44// #2023_05_03_Time_172_ms_(100.00%)_Space_36.2_MB_(50.00%)
55
6- import java.util.Arrays
7-
86@Suppress(" NAME_SHADOWING" )
97class Solution {
108 fun prisonAfterNDays (cells : IntArray , n : Int ): IntArray {
@@ -20,7 +18,7 @@ class Solution {
2018 day++
2119 n--
2220 val next = getNextDay(prev)
23- if (Arrays .equals(next, first)) {
21+ if (next.contentEquals( first)) {
2422 period = day - 1
2523 n % = period
2624 }
Original file line number Diff line number Diff line change @@ -3,11 +3,9 @@ package g1001_1100.s1024_video_stitching
33// #Medium #Array #Dynamic_Programming #Greedy
44// #2023_05_22_Time_141_ms_(100.00%)_Space_34.8_MB_(100.00%)
55
6- import java.util.Arrays
7-
86class Solution {
97 fun videoStitching (clips : Array <IntArray >, time : Int ): Int {
10- Arrays .sort( clips) { a: IntArray , b: IntArray ->
8+ clips.sortWith { a: IntArray , b: IntArray ->
119 if (a[0 ] == b[0 ]
1210 ) a[1 ] - b[1 ] else a[0 ] - b[0 ]
1311 }
Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ package g1001_1100.s1027_longest_arithmetic_subsequence
33// #Medium #Array #Hash_Table #Dynamic_Programming #Binary_Search
44// #2023_05_23_Time_330_ms_(100.00%)_Space_101.4_MB_(16.67%)
55
6- import java.util.Arrays
7-
86class Solution {
97 fun longestArithSeqLength (nums : IntArray ): Int {
108 val max = maxElement(nums)
@@ -13,7 +11,7 @@ class Solution {
1311 val n = nums.size
1412 val dp = Array (n) { IntArray (2 * diff + 2 ) }
1513 for (d in dp) {
16- Arrays .fill(d, 1 )
14+ d .fill(1 )
1715 }
1816 var ans = 0
1917 for (i in 0 until n) {
Original file line number Diff line number Diff line change @@ -2,11 +2,9 @@ package g1001_1100.s1029_two_city_scheduling
22
33// #Medium #Array #Sorting #Greedy #2023_05_24_Time_148_ms_(100.00%)_Space_35.4_MB_(92.31%)
44
5- import java.util.Arrays
6-
75class Solution {
86 fun twoCitySchedCost (costs : Array <IntArray >): Int {
9- Arrays .sort( costs) { a: IntArray , b: IntArray ->
7+ costs.sortWith { a: IntArray , b: IntArray ->
108 a[0 ] - a[1 ] - (b[0 ] - b[1 ])
119 }
1210 var cost = 0
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package g1001_1100.s1081_smallest_subsequence_of_distinct_characters
33// #Medium #String #Greedy #Stack #Monotonic_Stack
44// #2023_06_02_Time_146_ms_(100.00%)_Space_34_MB_(100.00%)
55
6- import java.util.Arrays
76import java.util.Deque
87import java.util.LinkedList
98
@@ -13,7 +12,7 @@ class Solution {
1312 val stk: Deque <Char > = LinkedList ()
1413 val freq = IntArray (26 )
1514 val exist = BooleanArray (26 )
16- Arrays .fill(exist, false )
15+ exist .fill(false )
1716 for (ch in s.toCharArray()) {
1817 freq[ch.code - ' a' .code]++
1918 }
Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ package g1201_1300.s1235_maximum_profit_in_job_scheduling
33// #Hard #Array #Dynamic_Programming #Sorting #Binary_Search
44// #2023_06_09_Time_370_ms_(100.00%)_Space_49.5_MB_(84.00%)
55
6- import java.util.Arrays
7-
86class Solution {
97 fun jobScheduling (startTime : IntArray , endTime : IntArray , profit : IntArray ): Int {
108 val n = startTime.size
@@ -14,7 +12,7 @@ class Solution {
1412 time[i][1 ] = endTime[i]
1513 time[i][2 ] = profit[i]
1614 }
17- Arrays .sort( time, { a: IntArray , b: IntArray -> a[1 ].compareTo(b[1 ]) })
15+ time.sortWith { a: IntArray , b: IntArray -> a[1 ].compareTo(b[1 ]) }
1816 val maxP = Array (n) { IntArray (2 ) }
1917 var lastPos = - 1
2018 var currProfit: Int
Original file line number Diff line number Diff line change @@ -3,12 +3,11 @@ package g1301_1400.s1353_maximum_number_of_events_that_can_be_attended
33// #Medium #Array #Greedy #Heap_Priority_Queue
44// #2023_06_06_Time_728_ms_(100.00%)_Space_103.1_MB_(80.00%)
55
6- import java.util.Arrays
76import java.util.PriorityQueue
87
98class Solution {
109 fun maxEvents (events : Array <IntArray >): Int {
11- Arrays .sort( events) { a: IntArray , b: IntArray -> a[0 ] - b[0 ] }
10+ events.sortWith { a: IntArray , b: IntArray -> a[0 ] - b[0 ] }
1211 var ans = 0
1312 var i = 0
1413 val pq = PriorityQueue <Int >()
Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ package g1301_1400.s1366_rank_teams_by_votes
33// #Medium #Array #String #Hash_Table #Sorting #Counting
44// #2023_06_06_Time_179_ms_(100.00%)_Space_36.9_MB_(93.33%)
55
6- import java.util.Arrays
7-
86class Solution {
97 internal class Node (var c : Char ) {
108 var count = IntArray (26 )
@@ -20,9 +18,8 @@ class Solution {
2018 nodes[vote[i].code - ' A' .code]!! .count[i]++
2119 }
2220 }
23- Arrays .sort(
24- nodes
25- ) { o1: Node ? , o2: Node ? ->
21+
22+ nodes.sortWith sort@{ o1: Node ? , o2: Node ? ->
2623 for (i in 0 .. 25 ) {
2724 if (o1!! .count[i] != o2!! .count[i]) {
2825 return @sort o2.count[i] - o1.count[i]
You can’t perform that action at this time.
0 commit comments