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
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ