Skip to content

Commit aa0de6c

Browse files
add 2200
1 parent e93ed4b commit aa0de6c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

contest/src/main/java/com/github/contest/Execute.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import java.util.TreeMap
1616

1717
fun main() {
1818

19-
hammingWeight(11).also { println(it) }
19+
val str: String? = "ghdirfghdi"
2020

2121
}
2222

contest/src/main/java/com/github/contest/twoPointer/TwoPointerLeetCode.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,22 @@ fun trap(height: IntArray): Int {
4848
}
4949

5050
return water
51+
}
52+
53+
/**
54+
* 2200. Find All K-Distant Indices in an Array
55+
*/
56+
57+
fun findKDistantIndices(nums: IntArray, key: Int, k: Int): List<Int> {
58+
val result = mutableSetOf<Int>()
59+
for (j in nums.indices) {
60+
if (nums[j] == key) {
61+
val start = maxOf(0, j - k)
62+
val end = minOf(nums.size - 1, j + k)
63+
for (i in start..end) {
64+
result.add(i)
65+
}
66+
}
67+
}
68+
return result.sorted()
5169
}

0 commit comments

Comments
 (0)