We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9a129c6 commit d6e47feCopy full SHA for d6e47fe
1 file changed
contains-duplicate/heesun-task.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {boolean}
4
+ */
5
+ /*
6
+ Goal: return true if duplicated #, false if no duplicated number
7
+
8
+ Plan:
9
+ - create a Set
10
+ - loop num in nums
11
+ - num exists in the Set -> return true
12
+ - not exsits -> add the num in the Set, continue to the next loop
13
+ - return false
14
15
+ space complexity: O(n)
16
+ time complexity: O(n)
17
18
+var containsDuplicate = function(nums) {
19
+ const seen = new Set();
20
21
+ for(const num of nums) {
22
+ if (seen.has(num)) return true;
23
+ seen.add(num);
24
+ }
25
+ return false;
26
+};
0 commit comments