Skip to content

Commit

Permalink
Add #6 단속카메라 - 지선아
Browse files Browse the repository at this point in the history
  • Loading branch information
suna-ji authored Dec 1, 2024
1 parent 3bbc25a commit 2c3af2f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions greedy/단속카메라/지선아.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.*;
class Solution {
public int solution(int[][] routes) {
Arrays.sort(routes, Comparator.comparingInt(a -> a[1])); // 끝나는 지점으로 정렬
int count = 0;
int lastCam = Integer.MIN_VALUE;

for (int[] route : routes) {
if (lastCam < route[0]) {
count++;
lastCam = route[1];
}
}
return count;
}
}

0 comments on commit 2c3af2f

Please sign in to comment.