https://school.programmers.co.kr/learn/courses/30/lessons/42884
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
[JAVA]
import java.util.*;
class Solution {
public int solution(int[][] routes) {
int answer = 1;
//도로의 끝나는 지점을 기준으로 정렬합니다.
Arrays.sort(routes, (o1, o2) -> o1[1] - o2[1]);
int current_end = routes[0][1];
for(int i = 0; i < routes.length; i++){
//현재 끝나는 지점 보다 시작 지점이 빠른 경우 현재 끝나는 지점을 갱신합니다.
if(routes[i][0] > current_end){
current_end = routes[i][1];
answer++;
}
}
return answer;
}
}
'algorithm > 프로그래머스' 카테고리의 다른 글
프로그래머스_가장 먼 노드(JAVA) (0) | 2023.03.31 |
---|---|
프로그래머스_도둑질(JAVA) (0) | 2023.02.28 |
프로그래머스_섬 연결하기(JAVA) (0) | 2022.11.21 |
프로그래머스_구명보트(JAVA) (0) | 2022.11.21 |
프로그래머스_큰 수 만들기(JAVA) (0) | 2022.11.21 |