-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHW_42884.java
More file actions
22 lines (19 loc) ยท 810 Bytes
/
HW_42884.java
File metadata and controls
22 lines (19 loc) ยท 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// ๋ชจ๋ ์ฐจ๋์ด ํ๋ฒ์ ๋จ์์ฉ ์นด๋ฉ๋ผ๋ฅผ ๋ง๋๋๋กํ๋ ์ต์ ์นด๋ฉ๋ผ ์ค์น ๊ฐ์
import java.util.*;
class HW_42884 {
public int solution(int[][] routes) {
Arrays.sort(routes, (a,b) -> Integer.compare(a[1], b[1])); // ๋๊ฐ ์ง์ ๊ธฐ์ค ์ ๋ ฌ
// ๋จ์์นด๋ฉ๋ผ ํ์
int cnt = 0; // ์นด๋ฉ๋ผ ๊ฐ์
int endCamera= Integer.MIN_VALUE; // ์ฒ์์ ์นด๋ฉ๋ผ ์ค์นX
for(int i=0; i<routes.length; i++){
int s = routes[i][0]; // ์ง์
์ง์
int e = routes[i][1]; // ์ง์ถ ์ง์ (๋๊ฐ)
if(endCamera<s){ // ์ค์น๋์ง ์์ ์ง์
cnt++; // ์นด๋ฉ๋ผ ์ค์น
endCamera = e; // ๋๊ฐ๋ ์ง์ ์ ์นด๋ฉ๋ผ ์ค์น!
}
}
return cnt;
}
}