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 0fc7ec8 commit 36bdbb8Copy full SHA for 36bdbb8
1 file changed
contains-duplicate/samcho0608.java
@@ -0,0 +1,16 @@
1
+import java.util.HashSet;
2
+
3
+class Solution {
4
+ // return: does any value appear more than once in the array
5
+ // Time Complexity: O(n)
6
+ // Space Complexity: O(n)
7
+ public boolean containsDuplicate(int[] nums) {
8
+ HashSet<Integer> uniqNums = new HashSet<>();
9
10
+ for(int num : nums) {
11
+ if(!uniqNums.add(num)) return true;
12
+ }
13
14
+ return false;
15
16
+}
0 commit comments