Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- algorithum
- findDulicate
- 6월 첼린지
- 코테
- string
- 코딩 테스트
- linked list
- 맛집
- LeetCode
- tree
- 른당사피
- invert Binary Tree
- Python
- 사당돈
- two sum
- 발리인망원
- algorithm
- prefix sum
- 알탕뚝배기
- map
- 알고리즘
- 해물감성포차
- Array
- 코딩 테세트
- two pointers
- 발리 음식
- java
- 망원 밥집
- Find the Duplicate Number
- 투포인터
Archives
- Today
- Total
기록하는 공간
[leetcode/java] 287. Find the Duplicate Number 본문
Map을 이용한 풀이
class Solution {
public int findDuplicate(int[] nums) {
int duplicateNumber = 0;
int numsLength = nums.length;
Map<Integer, Integer> map = new HashMap<>();
for (int i : nums) {
map.put(i, map.getOrDefault(i, 0) + 1);
if (map.get(i) > 1) duplicateNumber = i;
}
return duplicateNumber;
}
}
'알고리즘 > leetcode' 카테고리의 다른 글
[leetcode/java] 226. Invert Binary Tree (0) | 2020.06.01 |
---|---|
[leetcode/java] 367. Valid Perfect Square (0) | 2020.05.09 |
[leetcode/java] 1427.Perform String Shifts (0) | 2020.04.15 |
[leetcode/java]844. Backspace String Compare (0) | 2020.04.10 |
[leetcode/java] 617.Merge Two Binary Trees (0) | 2020.02.23 |
Comments