Skip to content

Commit 2356501

Browse files
committed
feat(leetcode/217): Solve Contains Duplicate (Easy)
1 parent 1317ce6 commit 2356501

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

contains-duplicate/renovizee.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
13

4+
// tag renovizee 1week
25
// https://github.com/DaleStudy/leetcode-study/issues/217
36
// https://leetcode.com/problems/contains-duplicate/
47
class Solution {
58
public boolean containsDuplicate(int[] nums) {
6-
7-
return true;
9+
Map<Integer,Integer> countMap = new HashMap<>();
10+
for (int num : nums) {
11+
int count = countMap.getOrDefault(num, 0);
12+
int addCount = count + 1;
13+
countMap.put(num, addCount);
14+
if (addCount == 2) {
15+
return true;
16+
}
17+
}
18+
return false;
819
}
920
}
21+
22+
//-------------------------------------------------------------------------------------------------------------
23+
// 기본 문법 피드백
24+
// 1) Map 기본 문법, ~.getOrDefault()
25+
//-------------------------------------------------------------------------------------------------------------

two-sum/renovizee.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java.util.HashMap;
22
import java.util.Map;
33

4-
// tag renovizee
4+
// tag renovizee 1week
55
// https://github.com/DaleStudy/leetcode-study/issues/219
66
// https://leetcode.com/problems/two-sum/description/
77

0 commit comments

Comments
 (0)