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 9e2dbc7 commit f9870c8Copy full SHA for f9870c8
contains-duplicate/mkwkw.java
@@ -1,18 +1,20 @@
1
-//using map
+//1. using map
2
+//2. using set : why? It doesn't have to use a pair of key and value.
3
4
class Solution {
5
public boolean containsDuplicate(int[] nums) {
- Map<Integer, Boolean> appearance = new HashMap<>();
6
+ //Map<Integer, Boolean> appearance = new HashMap<>();
7
+ Set<Integer> appearance = new HashSet<>();
8
9
for(int i=0; i<nums.length; i++)
10
{
- if(appearance.containsKey(nums[i]))
11
+ if(appearance.contains(nums[i]))
12
13
return true;
14
}
15
else
16
- appearance.put(nums[i], true);
17
+ appearance.add(nums[i]);
18
19
20
0 commit comments