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 |
Tags
- 파이썬
- greedy
- 코테
- 자바
- hash table
- Tree
- dynamic programming
- Number Theory
- SQL
- Stack
- Matrix
- 구현
- Method
- Binary Search
- Data Structure
- geometry
- Math
- Class
- array
- Binary Tree
- two pointers
- database
- Counting
- simulation
- implement
- 코딩테스트
- sorting
- string
- bit manipulation
- java
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2248. Intersection of Multiple Arrays 본문
1. Input
1) int[][] nums
2. Output
1) 모든 행에 나오는 정수를 담은 리스트를 반환
- 정렬은 오름차순으로 한다.
- 각 행에는 중복 요소가 없다.
3. Constraint
1) 1 <= nums.length <= 1000
2) 1 <= sum(nums[i].length) <= 1000
3) 1 <= nums[i][j] <= 1000
4. Example
Input: nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]] -> Output: [3,4]
Input: nums = [[1,2,3],[4,5,6]] -> Output: []
5. Code
1) 첫 코드(2023/04/30)
class Solution {
public List<Integer> intersection(int[][] nums) {
List<Integer> answer = new ArrayList<>();
HashMap<Integer,Integer> map = new HashMap<>();
for(int i=0 ; i<nums.length ; i++)
for(int j=0 ; j<nums[i].length ; j++)
map.put(nums[i][j], map.getOrDefault(nums[i][j],0)+1);
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Map.Entry e = (Map.Entry)it.next();
if((int)e.getValue()==nums.length)
answer.add((int)e.getKey());
}
answer.sort(Comparator.naturalOrder());
return answer;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2287. Rearrange Characters to Make Target String (0) | 2023.04.30 |
---|---|
[LeetCode/Easy] 2259. Remove Digit From Number to Maximize Result (0) | 2023.04.30 |
[LeetCode/Easy] 2239. Find Closest Number to Zero (0) | 2023.04.30 |
[LeetCode/Easy] 2215. Find the Difference of Two Arrays (0) | 2023.04.28 |
[LeetCode/Easy] 2206. Divide Array Into Equal Pairs (0) | 2023.04.28 |