存在重复元素III

在整数数组 nums 中,是否存在两个下标 i 和 j,使得 nums [i] 和 nums [j] 的差的绝对值小于等于 t ,且满足 i 和 j 的差的绝对值也小于等于 k。

如果存在则返回 true,不存在返回 false。

function containsNearbyAlmostDuplicate(nums, k, t) {
    for(let i = 0;i < nums.length - 1;i++){
        let item = nums[i]
        for(let j = i + 1;j < nums.length;j++){
            let jItem = nums[j]
            if(Math.abs(item - jItem) <= t && Math.abs(i - j) <= k){
                return true
            }
        }
    }
    return false
}

Leecode提交通过

以自己现在的努力程度,还没有资格和别人拼天赋
原文地址:https://www.cnblogs.com/zhenjianyu/p/13398635.html