
Solution 1) 다른 사람의 풀이
import java.util.HashMap;
import java.util.Map;
class Solution {
public int solution(int[][] lines) {
Map<Integer, Integer> map = new HashMap<>();
for (int i=0; i<lines.length; i++) {
int min = Math.min(lines[i][0], lines[i][1]);
int max = Math.max(lines[i][0], lines[i][1]);
for (int j=min; j<max; j++) {
map.put(j, map.getOrDefault(j, 0) + 1);
}
}
int answer = 0;
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (entry.getValue() >= 2) {
answer++;
}
}
return answer;
}
}
코드 및 문제 리뷰
다시 확인 후 작성해야함
'연습문제 > 프로그래머스, 입문' 카테고리의 다른 글
| [프로그래머스 입문_java] 특이한 정렬 (0) | 2023.11.08 |
|---|---|
| [프로그래머스 입문_java] 평행 (재공부) (0) | 2023.11.08 |
| [프로그래머스 입문_java] 유한소수 판별하기 (0) | 2023.11.07 |
| [프로그래머스 입문_java] 저주의 숫자 3 (0) | 2023.11.07 |
| [프로그래머스 입문_java] 숨어있는 숫자의 덧셈(2) (0) | 2023.11.06 |