Skip to content

Commit 07a9ad9

Browse files
committed
[level 0] Title: 겹치는 선분의 길이, Time: 0.09 ms, Memory: 93 MB -BaekjoonHub
1 parent 581ba60 commit 07a9ad9

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

프로그래머스/0/120876. 겹치는 선분의 길이/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 80.5 MB, 시간: 0.04 ms
7+
메모리: 93 MB, 시간: 0.09 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 03월 11일 23:25:41
19+
2025년 03월 11일 23:43:29
2020

2121
### 문제 설명
2222

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
class Solution {
22
public int solution(int[][] lines) {
3-
int[] arr = new int[200];
43
int answer = 0;
5-
6-
for (int i = 0; i < lines.length; i++) {
7-
for (int j = lines[i][0] + 100; j < lines[i][1] + 100; j++) {
8-
arr[j]++;
9-
}
10-
}
11-
12-
for (int i = 0; i < 200; i++) {
13-
if (arr[i] > 1) {
14-
answer++;
4+
5+
for (int i = -100; i < 100; i++) {
6+
int count = 0;
7+
8+
// 모든 선분을 확인하여 겹치는 개수 카운트
9+
for (int[] line : lines) {
10+
if (line[0] <= i && line[1] > i) {
11+
count++;
12+
}
1513
}
14+
15+
// 두 개 이상 겹치는 경우 answer 증가
16+
if (count > 1) answer++;
1617
}
18+
1719
return answer;
1820
}
1921
}

0 commit comments

Comments
 (0)