Skip to content
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
6 changes: 0 additions & 6 deletions app/src/main/java/com/leetcode_kotlin/Executing.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.leetcode_kotlin

import java.util.concurrent.ConcurrentHashMap


/**
* Executing
Expand All @@ -10,10 +8,6 @@ import java.util.concurrent.ConcurrentHashMap

fun main() {

val concurrentHashMap = ConcurrentHashMap<Int, Int>()

concurrentHashMap.put(1, 5)


}

Expand Down
5 changes: 2 additions & 3 deletions contest/src/main/java/com/github/contest/Execute.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.contest


import com.github.contest.bitManipulation.hammingWeight
import com.github.contest.math.numberOfPowerfulInt
import com.github.contest.slidingWindow.customStructure.rabinKarpMultiPattern
import com.github.contest.slidingWindow.customStructure.slidingWindowClassic
Expand All @@ -15,9 +16,7 @@ import java.util.TreeMap

fun main() {

val str = "abcdefrt"

str.chunked(3).also { println(it) }
val str: String? = "ghdirfghdi"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,36 @@ fun subsetXORSum(nums: IntArray): Int {

calculateSubsetXOR(0, 0)
return totalXORSum
}

/**
* 191. Number of 1 Bits
*/

fun hammingWeight(n: Int): Int {
var num = n
var count = 0

while (num != 0) {
count += num and 1
num = num ushr 1
}

return count
}

/**
* 461. Hamming Distance
*/

fun hammingDistance(x: Int, y: Int): Int {
var res = x xor y
var count = 0

while (res != 0) {
count += res and 1
res = res ushr 1
}

return count
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,22 @@ fun trap(height: IntArray): Int {
}

return water
}

/**
* 2200. Find All K-Distant Indices in an Array
*/

fun findKDistantIndices(nums: IntArray, key: Int, k: Int): List<Int> {
val result = mutableSetOf<Int>()
for (j in nums.indices) {
if (nums[j] == key) {
val start = maxOf(0, j - k)
val end = minOf(nums.size - 1, j + k)
for (i in start..end) {
result.add(i)
}
}
}
return result.sorted()
}