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 ;
13
4+ // tag renovizee 1week
25// https://github.com/DaleStudy/leetcode-study/issues/217
36// https://leetcode.com/problems/contains-duplicate/
47class 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+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change 11import java .util .HashMap ;
22import 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
You can’t perform that action at this time.
0 commit comments