From 2c3af2f266c31da60b0cd6efd60fca649bc64e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=80=EC=84=A0=EC=95=84?= Date: Sun, 1 Dec 2024 13:32:29 +0900 Subject: [PATCH] =?UTF-8?q?Add=20#6=20=EB=8B=A8=EC=86=8D=EC=B9=B4=EB=A9=94?= =?UTF-8?q?=EB=9D=BC=20-=20=EC=A7=80=EC=84=A0=EC=95=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\247\200\354\204\240\354\225\204.java" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "greedy/\353\213\250\354\206\215\354\271\264\353\251\224\353\235\274/\354\247\200\354\204\240\354\225\204.java" diff --git "a/greedy/\353\213\250\354\206\215\354\271\264\353\251\224\353\235\274/\354\247\200\354\204\240\354\225\204.java" "b/greedy/\353\213\250\354\206\215\354\271\264\353\251\224\353\235\274/\354\247\200\354\204\240\354\225\204.java" new file mode 100644 index 0000000..e0cb1cd --- /dev/null +++ "b/greedy/\353\213\250\354\206\215\354\271\264\353\251\224\353\235\274/\354\247\200\354\204\240\354\225\204.java" @@ -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; + } +}