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