File tree Expand file tree Collapse file tree 2 files changed +15
-13
lines changed
프로그래머스/0/120876. 겹치는 선분의 길이 Expand file tree Collapse file tree 2 files changed +15
-13
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 80.5 MB, 시간: 0.04 ms
7+ 메모리: 93 MB, 시간: 0.09 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 03월 11일 23:25:41
19+ 2025년 03월 11일 23:43:29
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 11class 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}
You can’t perform that action at this time.
0 commit comments