Skip to content
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

Fixed Idea warnings #785

Merged
merged 2 commits into from
Mar 26, 2025
Merged
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
@@ -4,7 +4,7 @@ package g0001_0100.s0034_find_first_and_last_position_of_element_in_sorted_array
// #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_5 #Top_Interview_150_Binary_Search
// #Big_O_Time_O(log_n)_Space_O(1) #2023_07_05_Time_174_ms_(100.00%)_Space_37.8_MB_(71.70%)

class Solution constructor() {
class Solution {
fun searchRange(nums: IntArray, target: Int): IntArray {
val ans = IntArray(2)
ans[0] = helper(nums, target, false)
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ class Solution {
startWord = i + 1
// resetting these to 0 for processing next line
lineTotal = 0
numWordsOnLine = lineTotal
numWordsOnLine = 0
// need a new StringBuilder for the next line
sb = StringBuilder(maxWidth)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/g0201_0300/s0289_game_of_life/Solution.kt
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ class Solution {
}

private fun compute(board: Array<IntArray>, r: Int, c: Int): Int {
var ret: Int = 0
var ret = 0
for (arr in dim) {
val row = arr[0] + r
val col = arr[1] + c
5 changes: 1 addition & 4 deletions src/main/kotlin/g0201_0300/s0292_nim_game/Solution.kt
Original file line number Diff line number Diff line change
@@ -4,9 +4,6 @@ package g0201_0300.s0292_nim_game

class Solution {
fun canWinNim(n: Int): Boolean {
if (n % 4 == 0) {
return false
}
return true
return n % 4 != 0
}
}
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@ package g0301_0400.s0304_range_sum_query_2d_immutable
// #2022_11_07_Time_1373_ms_(85.71%)_Space_129.1_MB_(75.00%)

class NumMatrix(matrix: Array<IntArray>) {
private val M = matrix.size
private val N = if (M > 0) matrix[0].size else 0
private val m = matrix.size
private val n = if (m > 0) matrix[0].size else 0

var array = Array<IntArray> (M + 1) { IntArray(N + 1) }
var array = Array<IntArray> (m + 1) { IntArray(n + 1) }

init {
for (i in 1..M) {
for (j in 1..N) {
for (i in 1..m) {
for (j in 1..n) {
array[i][j] = matrix[i - 1][j - 1] + array[i][j - 1] + array[i - 1][j] - array[i - 1][j - 1]
}
}
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ class Solution {
while (queue.isNotEmpty()) {
val size = queue.size
val newLeaves = mutableListOf<Int>()
for (_sz in 0 until size) {
for (sz in 0 until size) {
val cur = queue.removeFirst()
newLeaves.add(cur)
for (next in graph[cur]) {
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ class Solution {
while (ei < nums.size) {
val l = if (si - 1 == -1) 1 else nums[si - 1]
val r = if (ei + 1 == nums.size) 1 else nums[ei + 1]
var maxAns = -1e7.toInt()
var maxAns = (-1e7).toInt()
for (cut in si..ei) {
val leftAns = if (si == cut) 0 else dp[si][cut - 1]
val rightAns = if (ei == cut) 0 else dp[cut + 1][ei]
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ class Solution {
for (c in s.toCharArray()) {
set.flip(c.code - 'A'.code)
}
return if (set.isEmpty()) {
return if (set.isEmpty) {
s.length
} else {
s.length - set.cardinality() + 1
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ class Solution {
}

private fun make(cur: String): Node {
val ans: Node = Node()
val ans = Node()
val tmp: MutableList<String> = ArrayList()
if (Character.isDigit(cur[0])) {
ans.update(tmp, Integer.valueOf(cur))
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ class Solution {
val fmap: MutableMap<String, Int> = HashMap()
for (s in d) {
var rep = 0
var i: Int = 0
var i = 0
while (i < s.length) {
val c = s[i]
rep = if (c in '0'..'9') {
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ class Solution {
}

private fun product(vararg vals: Long): Long {
var product: Long = 1L
var product = 1L
for (`val`: Long in vals) {
product *= `val`
}
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ package g1701_1800.s1748_sum_of_unique_elements
class Solution {
fun sumOfUnique(nums: IntArray): Int {
val map: MutableMap<Int, Int> = HashMap()
var sum: Int = 0
var sum = 0
for (num: Int in nums) {
map.put(num, map.getOrDefault(num, 0) + 1)
}
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@ package g1701_1800.s1749_maximum_absolute_sum_of_any_subarray

class Solution {
fun maxAbsoluteSum(nums: IntArray): Int {
var min: Int = 0
var max: Int = 0
var s: Int = 0
var min = 0
var max = 0
var s = 0
for (num: Int in nums) {
s += num
min = Math.min(min, s)
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ class Solution {
) *
nums[cur]
) %
mod
MOD
)
}
dq.add(i)
@@ -59,7 +59,7 @@ class Solution {
getSum(nums, forward, prefix, backward, suffix, prev, cur, n) *
nums[cur]
) %
mod
MOD
)
}
return res.toInt()
@@ -75,34 +75,34 @@ class Solution {
cur: Int,
next: Int,
): Long {
val sum = (cur - prev) * nums[cur].toLong() % mod * (next - cur) % mod
val sum = (cur - prev) * nums[cur].toLong() % MOD * (next - cur) % MOD
val preSum = getPresum(backward, suffix, prev + 1, cur - 1, next - cur)
val postSum = getPostsum(forward, prefix, cur + 1, next - 1, cur - prev)
return (sum + preSum + postSum) % mod
return (sum + preSum + postSum) % MOD
}

private fun getPresum(backward: LongArray, suffix: LongArray, from: Int, to: Int, m: Int): Long {
val n = backward.size
val cnt = to - from + 1L
return (
(suffix[from] - suffix[to + 1] - cnt * (if (to + 1 == n) 0 else backward[to + 1]) % mod) %
mod
(suffix[from] - suffix[to + 1] - cnt * (if (to + 1 == n) 0 else backward[to + 1]) % MOD) %
MOD
* m %
mod
MOD
)
}

private fun getPostsum(forward: LongArray, prefix: LongArray, from: Int, to: Int, m: Int): Long {
val cnt = to - from + 1L
return (
(prefix[to + 1] - prefix[from] - cnt * (if (0 == from) 0 else forward[from - 1]) % mod) %
mod
(prefix[to + 1] - prefix[from] - cnt * (if (0 == from) 0 else forward[from - 1]) % MOD) %
MOD
* m %
mod
MOD
)
}

companion object {
private const val mod = 1e9.toInt() + 7
private const val MOD = 1e9.toInt() + 7
}
}
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ class Solution {
}
val num = IntArray(arr.size)
var i = arr.size - 1
for (I in arr) {
num[i--] = I
for (j in arr) {
num[i--] = j
}
return num
}
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ package g2501_2600.s2574_left_and_right_sum_differences
class Solution {
fun leftRightDifference(nums: IntArray): IntArray {
val n = nums.size
val ans: IntArray = IntArray(n)
val ans = IntArray(n)
var rightSum = nums.sum()
var leftSum = 0

Original file line number Diff line number Diff line change
@@ -6,22 +6,18 @@ package g2701_2800.s2729_check_if_the_number_is_fascinating
class Solution {
fun isFascinating(n: Int): Boolean {
val set = HashSet<Int>()
fun add(_cur: Int): Boolean {
var cur = _cur
while (cur > 0) {
val n = cur % 10
fun add(cur: Int): Boolean {
var localCur = cur
while (localCur > 0) {
val n = localCur % 10
if (n == 0 || set.contains(n)) {
return false
}
set.add(n)
cur /= 10
localCur /= 10
}
return true
}

if (!add(n) || !add(2 * n) || !add(3 * n)) {
return false
}
return true
return !(!add(n) || !add(2 * n) || !add(3 * n))
}
}
4 changes: 2 additions & 2 deletions src/test/kotlin/com_github_leetcode/NodeTest.kt
Original file line number Diff line number Diff line change
@@ -21,14 +21,14 @@ internal class NodeTest {

@Test
fun constructor3() {
val node: Node = Node(1, listOf(Node(2)))
val node = Node(1, listOf(Node(2)))
assertThat(node.`val`, equalTo(1))
assertThat(node.toString(), equalTo("[2]"))
}

@Test
fun constructor4() {
val node: Node = Node(
val node = Node(
1,
listOf(
Node(2, listOf(Node(3))),
Original file line number Diff line number Diff line change
@@ -8,9 +8,8 @@ internal class RandomizedSetTest {
@Test
fun randomizedSet() {
val result: MutableList<String> = ArrayList()
var randomizedSet: RandomizedSet? = null
result.add(randomizedSet.toString() + "")
randomizedSet = RandomizedSet()
result.add("null")
var randomizedSet = RandomizedSet()
result.add(randomizedSet.insert(1).toString() + "")
result.add(randomizedSet.remove(2).toString() + "")
result.add(randomizedSet.insert(2).toString() + "")