Skip to content

Commit a80cb2e

Browse files
authored
Improved tasks 2801-2824
1 parent 0e79631 commit a80cb2e

File tree

7 files changed

+5
-7
lines changed
  • src/main/kotlin/g2801_2900
    • s2808_minimum_seconds_to_equalize_a_circular_array
    • s2811_check_if_it_is_possible_to_split_array
    • s2812_find_the_safest_path_in_a_grid
    • s2815_max_pair_sum_in_an_array
    • s2816_double_a_number_represented_as_a_linked_list
    • s2817_minimum_absolute_difference_between_elements_with_constraint
    • s2818_apply_operations_to_maximize_score

7 files changed

+5
-7
lines changed

src/main/kotlin/g2801_2900/s2808_minimum_seconds_to_equalize_a_circular_array/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Solution {
1212
val hm = HashMap<Int, MutableList<Int>>()
1313
for (i in 0 until n) {
1414
val v = nums[i]
15-
hm.computeIfAbsent(v) { k: Int? -> ArrayList() }.add(i)
15+
hm.computeIfAbsent(v) { _: Int? -> ArrayList() }.add(i)
1616
}
1717
for (list in hm.values) {
1818
if (list.size > 1) {

src/main/kotlin/g2801_2900/s2811_check_if_it_is_possible_to_split_array/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package g2801_2900.s2811_check_if_it_is_possible_to_split_array
55

66
class Solution {
77
fun canSplitArray(nums: List<Int>, m: Int): Boolean {
8-
if (nums.size < 3 && !nums.isEmpty()) {
8+
if (nums.size < 3 && nums.isNotEmpty()) {
99
return true
1010
}
1111
var ans = false

src/main/kotlin/g2801_2900/s2812_find_the_safest_path_in_a_grid/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Solution {
6666
}
6767
var level = 1
6868
val dir = arrayOf(intArrayOf(1, 0), intArrayOf(0, 1), intArrayOf(-1, 0), intArrayOf(0, -1))
69-
while (!q.isEmpty()) {
69+
while (q.isNotEmpty()) {
7070
val len = q.size
7171
for (i in 0 until len) {
7272
val v = q.poll()

src/main/kotlin/g2801_2900/s2815_max_pair_sum_in_an_array/Solution.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package g2801_2900.s2815_max_pair_sum_in_an_array
33
// #Easy #Array #Hash_Table #2023_12_06_Time_223_ms_(82.35%)_Space_37.6_MB_(100.00%)
44

55
import java.util.PriorityQueue
6-
import kotlin.Comparator
76
import kotlin.collections.HashMap
87
import kotlin.math.max
98

src/main/kotlin/g2801_2900/s2816_double_a_number_represented_as_a_linked_list/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Solution {
3939

4040
private fun revList(head: ListNode?): ListNode? {
4141
var prev: ListNode? = null
42-
var nxt: ListNode? = null
42+
var nxt: ListNode?
4343
var current = head
4444
while (current != null) {
4545
nxt = current.next

src/main/kotlin/g2801_2900/s2817_minimum_absolute_difference_between_elements_with_constraint/Solution.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import kotlin.math.min
99

1010
class Solution {
1111
fun minAbsoluteDifference(nums: List<Int>, x: Int): Int {
12-
// if (x == 0) x = 1;
1312
val xt = TreeSet<Int>()
1413
val start = nums.size - 1 - x
1514
var j = nums.size - 1

src/main/kotlin/g2801_2900/s2818_apply_operations_to_maximize_score/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Solution {
2929
}
3030
// when an element is poped, its right bound is confirmed: (i - left + 1) * (right - i +
3131
// 1)
32-
while (!monoStack.isEmpty() && monoStack.peekFirst()[0] < score) {
32+
while (monoStack.isNotEmpty() && monoStack.peekFirst()[0] < score) {
3333
val popIndex = monoStack.pollFirst()[1]
3434
val actualRightIndexOfPopedElement = i - 1
3535
dp[popIndex] *= actualRightIndexOfPopedElement - popIndex + 1

0 commit comments

Comments
 (0)