Skip to content

Commit 487ab8a

Browse files
authored
Improved tasks 989-3400
1 parent 292cd87 commit 487ab8a

File tree

9 files changed

+15
-15
lines changed
  • src/main/kotlin
    • g0901_1000/s0989_add_to_array_form_of_integer
    • g1001_1100/s1048_longest_string_chain
    • g1601_1700/s1639_number_of_ways_to_form_a_target_string_given_a_dictionary
    • g2001_2100/s2019_the_score_of_students_solving_math_expression
    • g2401_2500/s2452_words_within_two_edits_of_dictionary
    • g3201_3300
    • g3401_3500

9 files changed

+15
-15
lines changed

Diff for: src/main/kotlin/g0901_1000/s0989_add_to_array_form_of_integer/Solution.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ package g0901_1000.s0989_add_to_array_form_of_integer
55

66
@Suppress("NAME_SHADOWING")
77
class Solution {
8-
fun addToArrayForm(num: IntArray, k: Int): List<Int?> {
8+
fun addToArrayForm(num: IntArray, k: Int): List<Int> {
99
var k = k
10-
val result = ArrayList<Int?>()
10+
val result = ArrayList<Int>()
1111
var carry = 0
1212
for (i in num.indices.reversed()) {
1313
val temp = num[i] + k % 10 + carry

Diff for: src/main/kotlin/g1001_1100/s1048_longest_string_chain/Solution.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package g1001_1100.s1048_longest_string_chain
55

66
class Solution {
77
fun longestStrChain(words: Array<String>): Int {
8-
val lenStr = arrayOfNulls<MutableList<String>?>(20)
8+
val lenStr = arrayOfNulls<MutableList<String>>(20)
99
for (word in words) {
1010
val len = word.length
1111
if (lenStr[len] == null) {

Diff for: src/main/kotlin/g1601_1700/s1639_number_of_ways_to_form_a_target_string_given_a_dictionary/Solution.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package g1601_1700.s1639_number_of_ways_to_form_a_target_string_given_a_dictiona
66
class Solution {
77
fun numWays(words: Array<String>, target: String): Int {
88
val counts = precompute(words)
9-
val memo = Array(target.length) { arrayOfNulls<Int?>(words[0].length) }
9+
val memo = Array(target.length) { arrayOfNulls<Int>(words[0].length) }
1010
return solve(memo, counts, words, target, 0, 0)
1111
}
1212

Diff for: src/main/kotlin/g2001_2100/s2019_the_score_of_students_solving_math_expression/Solution.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Solution {
1212
val st = ArrayDeque<Int>()
1313
val n = s.length
1414
var i = 0
15-
dp = Array(n) { arrayOfNulls<HashSet<Int>?>(n) }
15+
dp = Array(n) { arrayOfNulls<HashSet<Int>>(n) }
1616
while (i < n) {
1717
if (s[i].code - '0'.code >= 0 && s[i].code - '9'.code <= 0) {
1818
st.push(s[i].code - '0'.code)

Diff for: src/main/kotlin/g2401_2500/s2452_words_within_two_edits_of_dictionary/Solution.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Solution {
66
private var root: Node? = null
77

88
internal class Node {
9-
var childs = HashMap<Char, Node?>()
9+
var childs = HashMap<Char, Node>()
1010
}
1111

1212
private fun insert(s: String) {

Diff for: src/main/kotlin/g3201_3300/s3245_alternating_groups_iii/Solution.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package g3201_3300.s3245_alternating_groups_iii
55
import java.util.BitSet
66

77
class Solution {
8-
fun numberOfAlternatingGroups(colors: IntArray, queries: Array<IntArray>): MutableList<Int?> {
8+
fun numberOfAlternatingGroups(colors: IntArray, queries: Array<IntArray>): List<Int> {
99
val n = colors.size
1010
val set = BitSet()
1111
val bit = BIT(n)
@@ -14,7 +14,7 @@ class Solution {
1414
add(set, bit, n, i)
1515
}
1616
}
17-
val ans: MutableList<Int?> = ArrayList<Int?>()
17+
val ans: MutableList<Int> = ArrayList<Int>()
1818
for (q in queries) {
1919
if (q[0] == 1) {
2020
if (set.isEmpty) {

Diff for: src/main/kotlin/g3201_3300/s3283_maximum_number_of_moves_to_kill_all_pawns/Solution.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class Solution {
6161
if (x1 == x2 && y1 == y2) {
6262
return 0
6363
}
64-
val visited = Array<BooleanArray?>(50) { BooleanArray(50) }
64+
val visited = Array<BooleanArray>(50) { BooleanArray(50) }
6565
val queue: Queue<IntArray> = LinkedList<IntArray>()
6666
queue.offer(intArrayOf(x1, y1, 0))
67-
visited[x1]!![y1] = true
67+
visited[x1][y1] = true
6868
while (queue.isNotEmpty()) {
6969
val current = queue.poll()
7070
val x = current[0]
@@ -76,9 +76,9 @@ class Solution {
7676
if (nx == x2 && ny == y2) {
7777
return moves + 1
7878
}
79-
if (nx >= 0 && nx < 50 && ny >= 0 && ny < 50 && !visited[nx]!![ny]) {
79+
if (nx >= 0 && nx < 50 && ny >= 0 && ny < 50 && !visited[nx][ny]) {
8080
queue.offer(intArrayOf(nx, ny, moves + 1))
81-
visited[nx]!![ny] = true
81+
visited[nx][ny] = true
8282
}
8383
}
8484
}

Diff for: src/main/kotlin/g3401_3500/s3486_longest_special_path_ii/Solution.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Solution {
5353
if (last.containsKey(nums[nextNode])) {
5454
nextLeft.add(last[nums[nextNode]]!! + 1)
5555
}
56-
nextLeft.sortWith(Comparator.naturalOrder<Int?>())
56+
nextLeft.sortWith(Comparator.naturalOrder<Int>())
5757
while (nextLeft.size > 2) {
5858
nextLeft.removeAt(0)
5959
}

Diff for: src/main/kotlin/g3401_3500/s3490_count_beautiful_numbers/Solution.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Solution {
99

1010
private fun countBeautiful(x: Int): Int {
1111
val digits = getCharArray(x)
12-
val dp = HashMap<String?, Int?>()
12+
val dp = HashMap<String, Int>()
1313
return solve(0, 1, 0, 1, digits, dp)
1414
}
1515

@@ -24,7 +24,7 @@ class Solution {
2424
sum: Int,
2525
prod: Int,
2626
digits: CharArray,
27-
dp: HashMap<String?, Int?>,
27+
dp: HashMap<String, Int>,
2828
): Int {
2929
if (i == digits.size) {
3030
return if (sum > 0 && prod % sum == 0) {

0 commit comments

Comments
 (0)