-Code
class Solution {
public int solution(int[][] lines) {
int answer = 0;
int[] line = new int[201];
for (int[] el : lines) {
for (int i = el[0]; i < el[1] ; i++) {
line[i + 100] += 1;
if (line[i + 100] == 2) {
answer++;
}
}
}
return answer;
}
}
처음에는 라인을 계산 다하고 한번더 확인하는 식으로 해서 맞추었지만 더 속도를 올릴 방법이 떠올라서 다시 작성해서 통과했습니다.
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
[프로그래머스/Java] 옹알이 (1) (0) | 2025.02.21 |
---|---|
[프로그래머스/Java] 평행 (0) | 2025.02.21 |
[프로그래머스/Java] 안전지대 (0) | 2025.02.21 |
[프로그래머스/Java] 연속된 수의 합 (0) | 2025.02.21 |
[프로그래머스/Java] 다항식 더하기 (0) | 2025.02.21 |