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
- hash table
- Binary Tree
- 코테
- Counting
- geometry
- implement
- 구현
- Math
- Binary Search
- Stack
- Class
- Method
- Number Theory
- two pointers
- 코딩테스트
- Tree
- 자바
- array
- Matrix
- 파이썬
- database
- bit manipulation
- string
- simulation
- greedy
- sorting
- java
- dynamic programming
- Data Structure
- SQL
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Medium] 442. Find All Duplicates in an Array 본문
1. Input
1) int[] nums
// nums의 각 요소들은 1개 또는 2개 들어있다.
2. Output
1) nums에 2개씩 들어있는 요소를 담은 List<Integer>
3. Constraint
1) n == nums.length
2) 1 <= n <= 10^5
3) 1 <= nums[i] <= n
4. Example
Input: nums = [4,3,2,7,8,2,3,1] -> Output: [2,3]
5. Code
1) 첫 코드(2023/02/21)
List<Integer> answer = new ArrayList<Integer>();
HashSet s = new HashSet();
for(int i : nums){
if(s.contains(i)) answer.add(i);
else s.add(i);
}
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 455. Assign Cookies (0) | 2023.02.22 |
---|---|
[LeetCode/Medium] 454. 4Sum II (0) | 2023.02.22 |
[LeetCode/Medium] 438. Find All Anagrams in a String (0) | 2023.02.21 |
[프로그래머스/Lv.1] 카드 뭉치 (0) | 2023.02.20 |
[LeetCode/Easy] 409. Longest Palindrome (0) | 2023.02.19 |