From 726d307061986cd27644692402d36c7065085452 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 27 Aug 2025 13:13:29 +0900 Subject: [PATCH] =?UTF-8?q?[20250827]=20PGM=20/=20LV2=20/=20=EC=97=B0?= =?UTF-8?q?=EC=86=8D=EB=90=9C=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=97=B4?= =?UTF-8?q?=EC=9D=98=20=ED=95=A9=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\227\264\354\235\230 \355\225\251.md" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "suyeun84/202508/27 PGM LV2 \354\227\260\354\206\215\353\220\234 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.md" diff --git "a/suyeun84/202508/27 PGM LV2 \354\227\260\354\206\215\353\220\234 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.md" "b/suyeun84/202508/27 PGM LV2 \354\227\260\354\206\215\353\220\234 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.md" new file mode 100644 index 00000000..035a31b3 --- /dev/null +++ "b/suyeun84/202508/27 PGM LV2 \354\227\260\354\206\215\353\220\234 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.md" @@ -0,0 +1,33 @@ +```java +import java.util.*; +class Solution { + public int[] solution(int[] sequence, int k) { + List list = new ArrayList<>(); + int start = 0, end = 0, sum = sequence[0]; + while (start < sequence.length && end < sequence.length) { + if (sum == k) { + list.add(new int[] {start, end}); + } + if (sum <= k) { + end++; + if (end < sequence.length) + sum += sequence[end]; + } else { + if (start < sequence.length) + sum -= sequence[start]; + start++; + } + } + Collections.sort(list, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + int len1 = o1[1] - o1[0]; + int len2 = o2[1] - o2[0]; + return len1 - len2; + } + }); + int[] answer = {list.get(0)[0], list.get(0)[1]}; + return answer; + } +} +```