Skip to content

Commit f69468c

Browse files
committed
contains duplicates solution
1 parent d64c4ae commit f69468c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

contains-duplicate/yoonthecoder.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var containsDuplicate = function (nums) {
2+
// Create a set from the nums array. Since Sets only allow unique values, any duplicates will be removed.
3+
const set = new Set(nums);
4+
// Compare the size of the set and the length of the original array.- if the size of the set is smaller than the length of the original array('nums'), it means there were duplicates.
5+
6+
return set.size < nums.length;
7+
};
8+
9+
// Time Complexity: O(n); - adding elements to the Set & compare sizes
10+
// Space Complexity: O(n)

0 commit comments

Comments
 (0)