1. ๋ฌธ์ : https://school.programmers.co.kr/learn/courses/30/lessons/181188
2. ํ์ด
์์ ๊ฐ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ ํ
๊ทธ๋ฆฌ๋ํ๊ฒ ๋ค์ ์์ ๊ฐ์ ์ด์ ๋๋๋ ๊ฐ๊ณผ ๋น๊ตํ๋ฉฐ, ๊ทธ ์์ ๋ ๋ค๋ฉด ๋์ด๊ฐ๊ณ ๊ทธ ์์ ๋ค์ง ์๋๋ค๋ฉด (tagets[i][0] >= before)
before๊ฐ์ ์ ๋ฐ์ดํธํด์ฃผ๊ณ ๋ฏธ์ฌ์ผ ์ ++ ํด์ค๋ค.
3. ์ฝ๋
import java.util.*;
class Solution {
public int solution(int[][] targets) {
int answer = 0;
int before = 0;
Arrays.sort(targets, new Comparator<int[]>(){
@Override
public int compare(int[] obj1, int[] obj2){
if(obj1[1] > obj2[1]) return 1;
else return -1;
}
});
for(int i=0; i<targets.length; i++) {
System.out.println(targets[i][0]);
if(targets[i][0] >= before) {
before = targets[i][1];
answer++;
}
}
return answer;
}
}
'๐ป Coding Problems Solving > Greedy' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ 8980] ํ๋ฐฐ (0) | 2023.06.15 |
---|---|
[BOJ 1092] ๋ฐฐ (0) | 2023.06.06 |
[BOJ 2212] ์ผ์ (0) | 2023.06.05 |
[BOJ 13164] ํ๋ณต์ ์น์ (0) | 2023.05.30 |
[BOJ 1700] ๋ฉํฐํญ ์ค์ผ์ค๋ง (java) (0) | 2023.04.05 |
์ต๊ทผ๋๊ธ