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
- two pointers
- 파이썬
- bit manipulation
- Binary Search
- java
- Counting
- Class
- sorting
- simulation
- array
- string
- geometry
- 코테
- Stack
- Binary Tree
- 구현
- dynamic programming
- database
- greedy
- Method
- Number Theory
- SQL
- hash table
- Data Structure
- 코딩테스트
- Tree
- Math
- 자바
- implement
- Matrix
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1207. Unique Number of Occurrences 본문
1. Input
1) int[] arr
2. Output
1) arr의 요소에 대해 요소의 빈도 수를 파악한 뒤, 빈도 수에 중복이 없다면 true, 있다면 false를 반환
3. Constraint
1) 1 <= arr.length <= 1000
2) -1000 <= arr[i] <= 1000
4. Example
Input: arr = [1,2,2,1,1,3] -> Output: true
Input: arr= [1,2] -> Output: false
설명:
- 1은 3번, 2는 2번, 3은 1번 나타났으므로 빈도 수를 보면 [3, 2, 1]이고, 중복이 없으므로 true를 반환
- 1은 1번, 2도 1번이므로 빈도 수를 보면 [1,1]이고, 중복이 있으므로 false를 반환
5. Code
1) 첫 코드(2023/04/06)
HashMap<Integer,Integer> m = new HashMap<>();
for(int i : arr)
m.put(i, m.getOrDefault(i,0)+1);
HashSet<Integer> s = new HashSet<>();
Iterator it = m.entrySet().iterator();
boolean answer = true;
while(it.hasNext()){
int i = (int)((Map.Entry)it.next()).getValue();
if(s.contains(i)){
answer = false; break;
} else
s.add(i);
}
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1189. Maximum Number of Balloons (0) | 2023.04.06 |
---|---|
[LeetCode/Easy] 1200. Minimum Absolute Difference (0) | 2023.04.06 |
[LeetCode/Easy] 1217. Minimum Cost to Move Chips to The Same Position (0) | 2023.04.06 |
[LeetCode/Easy] 1232. Check If It Is a Straight Line (0) | 2023.04.06 |
[LeetCode/Easy] 1128. Number of Equivalent Domino Pairs (0) | 2023.04.06 |