Skip to content

Improved tasks 989-3400 #781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package g0901_1000.s0989_add_to_array_form_of_integer

@Suppress("NAME_SHADOWING")
class Solution {
fun addToArrayForm(num: IntArray, k: Int): List<Int?> {
fun addToArrayForm(num: IntArray, k: Int): List<Int> {
var k = k
val result = ArrayList<Int?>()
val result = ArrayList<Int>()
var carry = 0
for (i in num.indices.reversed()) {
val temp = num[i] + k % 10 + carry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package g1001_1100.s1048_longest_string_chain

class Solution {
fun longestStrChain(words: Array<String>): Int {
val lenStr = arrayOfNulls<MutableList<String>?>(20)
val lenStr = arrayOfNulls<MutableList<String>>(20)
for (word in words) {
val len = word.length
if (lenStr[len] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package g1601_1700.s1639_number_of_ways_to_form_a_target_string_given_a_dictiona
class Solution {
fun numWays(words: Array<String>, target: String): Int {
val counts = precompute(words)
val memo = Array(target.length) { arrayOfNulls<Int?>(words[0].length) }
val memo = Array(target.length) { arrayOfNulls<Int>(words[0].length) }
return solve(memo, counts, words, target, 0, 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Solution {
val st = ArrayDeque<Int>()
val n = s.length
var i = 0
dp = Array(n) { arrayOfNulls<HashSet<Int>?>(n) }
dp = Array(n) { arrayOfNulls<HashSet<Int>>(n) }
while (i < n) {
if (s[i].code - '0'.code >= 0 && s[i].code - '9'.code <= 0) {
st.push(s[i].code - '0'.code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Solution {
private var root: Node? = null

internal class Node {
var childs = HashMap<Char, Node?>()
var childs = HashMap<Char, Node>()
}

private fun insert(s: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package g3201_3300.s3245_alternating_groups_iii
import java.util.BitSet

class Solution {
fun numberOfAlternatingGroups(colors: IntArray, queries: Array<IntArray>): MutableList<Int?> {
fun numberOfAlternatingGroups(colors: IntArray, queries: Array<IntArray>): List<Int> {
val n = colors.size
val set = BitSet()
val bit = BIT(n)
Expand All @@ -14,7 +14,7 @@ class Solution {
add(set, bit, n, i)
}
}
val ans: MutableList<Int?> = ArrayList<Int?>()
val ans: MutableList<Int> = ArrayList<Int>()
for (q in queries) {
if (q[0] == 1) {
if (set.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class Solution {
if (x1 == x2 && y1 == y2) {
return 0
}
val visited = Array<BooleanArray?>(50) { BooleanArray(50) }
val visited = Array<BooleanArray>(50) { BooleanArray(50) }
val queue: Queue<IntArray> = LinkedList<IntArray>()
queue.offer(intArrayOf(x1, y1, 0))
visited[x1]!![y1] = true
visited[x1][y1] = true
while (queue.isNotEmpty()) {
val current = queue.poll()
val x = current[0]
Expand All @@ -76,9 +76,9 @@ class Solution {
if (nx == x2 && ny == y2) {
return moves + 1
}
if (nx >= 0 && nx < 50 && ny >= 0 && ny < 50 && !visited[nx]!![ny]) {
if (nx >= 0 && nx < 50 && ny >= 0 && ny < 50 && !visited[nx][ny]) {
queue.offer(intArrayOf(nx, ny, moves + 1))
visited[nx]!![ny] = true
visited[nx][ny] = true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Solution {
if (last.containsKey(nums[nextNode])) {
nextLeft.add(last[nums[nextNode]]!! + 1)
}
nextLeft.sortWith(Comparator.naturalOrder<Int?>())
nextLeft.sortWith(Comparator.naturalOrder<Int>())
while (nextLeft.size > 2) {
nextLeft.removeAt(0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Solution {

private fun countBeautiful(x: Int): Int {
val digits = getCharArray(x)
val dp = HashMap<String?, Int?>()
val dp = HashMap<String, Int>()
return solve(0, 1, 0, 1, digits, dp)
}

Expand All @@ -24,7 +24,7 @@ class Solution {
sum: Int,
prod: Int,
digits: CharArray,
dp: HashMap<String?, Int?>,
dp: HashMap<String, Int>,
): Int {
if (i == digits.size) {
return if (sum > 0 && prod % sum == 0) {
Expand Down