Skip to content

Commit ffa4cb7

Browse files
authored
Replaced Arrays.stream() with object methods
1 parent 7936e11 commit ffa4cb7

File tree

4 files changed

+6
-13
lines changed
  • src/main/kotlin

4 files changed

+6
-13
lines changed

src/main/kotlin/g0501_0600/s0552_student_attendance_record_ii/Solution.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package g0501_0600.s0552_student_attendance_record_ii
22

33
// #Hard #Dynamic_Programming #2023_01_17_Time_151_ms_(100.00%)_Space_33.3_MB_(100.00%)
44

5-
import java.util.Arrays
6-
75
@Suppress("NAME_SHADOWING")
86
class Solution {
97
fun checkRecord(n: Int): Int {
@@ -21,7 +19,7 @@ class Solution {
2119
)
2220
val e = quickPower(matrix, n - 1)
2321
return (
24-
(Arrays.stream(e[0]).sum() + Arrays.stream(e[1]).sum() + Arrays.stream(e[3]).sum()) %
22+
(e[0].sum() + e[1].sum() + e[3].sum()) %
2523
mod
2624
).toInt()
2725
}

src/main/kotlin/g0601_0700/s0679_24_game/Solution.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package g0601_0700.s0679_24_game
22

33
// #Hard #Array #Math #Backtracking #2023_02_16_Time_175_ms_(100.00%)_Space_34.7_MB_(100.00%)
44

5-
import java.util.Arrays
65
import kotlin.math.abs
76

87
class Solution {
9-
private fun backtrack(list: DoubleArray, n: Int): Boolean {
8+
private fun backtrack(list: Array<Double>, n: Int): Boolean {
109
if (n == 1) {
1110
return abs(list[0] - 24) < EPS
1211
}
@@ -51,7 +50,7 @@ class Solution {
5150
}
5251

5352
fun judgePoint24(nums: IntArray): Boolean {
54-
val a = Arrays.stream(nums).asDoubleStream().toArray()
53+
val a = nums.map { it.toDouble() }.toTypedArray()
5554
return backtrack(a, a.size)
5655
}
5756

src/main/kotlin/g0901_1000/s0954_array_of_doubled_pairs/Solution.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ package g0901_1000.s0954_array_of_doubled_pairs
33
// #Medium #Array #Hash_Table #Sorting #Greedy
44
// #2023_05_02_Time_462_ms_(100.00%)_Space_92.1_MB_(50.00%)
55

6-
import java.util.Arrays
7-
86
class Solution {
97
fun canReorderDoubled(arr: IntArray): Boolean {
10-
val max = 0.coerceAtLeast(Arrays.stream(arr).max().asInt)
11-
val min = 0.coerceAtMost(Arrays.stream(arr).min().asInt)
8+
val max = 0.coerceAtLeast(arr.max())
9+
val min = 0.coerceAtMost(arr.min())
1210
val positive = IntArray(max + 1)
1311
val negative = IntArray(-min + 1)
1412
for (a in arr) {

src/main/kotlin/g1001_1100/s1005_maximize_sum_of_array_after_k_negations/Solution.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package g1001_1100.s1005_maximize_sum_of_array_after_k_negations
22

33
// #Easy #Array #Sorting #Greedy #2023_05_15_Time_167_ms_(100.00%)_Space_36.5_MB_(20.00%)
44

5-
import java.util.Arrays
6-
75
@Suppress("NAME_SHADOWING")
86
class Solution {
97
fun largestSumAfterKNegations(nums: IntArray, k: Int): Int {
@@ -24,6 +22,6 @@ class Solution {
2422
if (k and 1 == 1) {
2523
nums[minIndex] *= -1
2624
}
27-
return Arrays.stream(nums).sum()
25+
return nums.sum()
2826
}
2927
}

0 commit comments

Comments
 (0)