Skip to content

Commit 1568018

Browse files
authored
Update containsDuplicate solution with minor index changes
https://leetcode.com/problems/contains-duplicate/discuss/60858/Possible-solutions
1 parent 285b307 commit 1568018

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

00_Arrays/ContainsDuplicate/JS/solution.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var containsDuplicateSort = function(nums) {
99
nums.sort((a, b) => a - b)
1010
// check if an array elements are equal next to each other
1111
// note that the limit is nums.length - 1
12-
for (let i=0; i < nums.length - 1; i++) {
13-
if (nums[i] === nums[i + 1]) return true
12+
for (let i=1; i < nums.length - 1; i++) {
13+
if (nums[i] === nums[i - 1]) return true
1414
}
1515
return false
1616
};
@@ -25,4 +25,4 @@ var containsDuplicate = function(nums) {
2525
set.add(nums[i])
2626
}
2727
return false
28-
};
28+
};

0 commit comments

Comments
 (0)