File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .HashMap ;
2
+ import java .util .Map ;
1
3
4
+ // tag renovizee 1week
2
5
// https://github.com/DaleStudy/leetcode-study/issues/217
3
6
// https://leetcode.com/problems/contains-duplicate/
4
7
class Solution {
5
8
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 ;
8
19
}
9
20
}
21
+
22
+ //-------------------------------------------------------------------------------------------------------------
23
+ // 기본 문법 피드백
24
+ // 1) Map 기본 문법, ~.getOrDefault()
25
+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change 1
1
import java .util .HashMap ;
2
2
import java .util .Map ;
3
3
4
- // tag renovizee
4
+ // tag renovizee 1week
5
5
// https://github.com/DaleStudy/leetcode-study/issues/219
6
6
// https://leetcode.com/problems/two-sum/description/
7
7
You can’t perform that action at this time.
0 commit comments