Skip to content

Commit 0adea9c

Browse files
committed
Contains Duplicate Solution
1 parent ee1ad8e commit 0adea9c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

contains-duplicate/naringst.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {boolean}
4+
*/
5+
6+
/**
7+
* Runtime: 89ms, Memory: 63MB
8+
*
9+
* Time complexity: O(n)
10+
* - To find the length of an array: O(n)
11+
* - Array to Set: O(n)
12+
* - To find the size of a set: O(n)
13+
* Space complexity: O(n)
14+
* - arrToSet: O(n)
15+
*
16+
* **/
17+
18+
var containsDuplicate = function (nums) {
19+
const arrLength = nums.length;
20+
const arrToSet = new Set(nums);
21+
const setLength = arrToSet.size;
22+
23+
if (arrLength !== setLength) {
24+
return true;
25+
}
26+
return false;
27+
};

0 commit comments

Comments
 (0)