Skip to content

Commit f9870c8

Browse files
committed
change: map -> set
1 parent 9e2dbc7 commit f9870c8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

contains-duplicate/mkwkw.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
//using map
1+
//1. using map
2+
//2. using set : why? It doesn't have to use a pair of key and value.
23

34
class Solution {
45
public boolean containsDuplicate(int[] nums) {
5-
Map<Integer, Boolean> appearance = new HashMap<>();
6+
//Map<Integer, Boolean> appearance = new HashMap<>();
7+
Set<Integer> appearance = new HashSet<>();
68

79
for(int i=0; i<nums.length; i++)
810
{
9-
if(appearance.containsKey(nums[i]))
11+
if(appearance.contains(nums[i]))
1012
{
1113
return true;
1214
}
1315
else
1416
{
15-
appearance.put(nums[i], true);
17+
appearance.add(nums[i]);
1618
}
1719
}
1820

0 commit comments

Comments
 (0)