Skip to content

Commit 692ae64

Browse files
committed
✨ contains duplicate iii
1 parent 004604b commit 692ae64

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} k
4+
* @param {number} t
5+
* @return {boolean}
6+
*/
7+
var containsNearbyAlmostDuplicate = function (nums, k, t) {
8+
for (let i = 0; i < nums.length; i++) {
9+
for (let j = i + 1; j < Math.min(nums.length, i + k + 1); j++) {
10+
if (Math.abs(nums[i] - nums[j]) <= t) {
11+
return true;
12+
}
13+
}
14+
}
15+
16+
return false;
17+
};
18+
19+
containsNearbyAlmostDuplicate([1, 2, 3, 1], 3, 0);

0 commit comments

Comments
 (0)