All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0201_0300.s0219_contains_duplicate_ii.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g0201_0300.s0219_contains_duplicate_ii

// #Easy #Array #Hash_Table #Sliding_Window #2022_10_25_Time_813_ms_(80.46%)_Space_71.1_MB_(81.22%)

class Solution {
    fun containsNearbyDuplicate(nums: IntArray, k: Int): Boolean {
        val map: MutableMap = HashMap()
        val len = nums.size
        for (i in 0 until len) {
            val index = map.put(nums[i], i)
            if (index != null && Math.abs(index - i) <= k) {
                return true
            }
        }
        return false
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy