Thanks to visit codestin.com
Credit goes to github.com

Skip to content

853. Car Fleet.java #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
Update 217-Contains-Duplicate.js
  • Loading branch information
bala2it4u authored Apr 7, 2022
commit a07bc37fc976686a116fa11a120a4722278c8bbc
15 changes: 9 additions & 6 deletions javascript/217-Contains-Duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
* @return {boolean}
*/
var containsDuplicate = function(nums) {
let map = new Set();
for (let idx=0;idx<nums.length;idx++){
if (map.has(nums[idx])) return true;

map.add(nums[idx]);
let map = {};

for (let i = 0; i < nums.length; i++) {
if (nums[i] in map) {
return true;
} else {
map[nums[i]] = i;
}
}
return false;
return false;
};