From 02658f587aaa484670cb9db7ec37de81bc2c1382 Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Sat, 10 Oct 2026 23:42:35 +0900 Subject: [PATCH 01/33] Create 593. Valid Square --- .../593. Valid Square" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/593. Valid Square" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/593. Valid Square" "b/leetcode3/\354\240\225\354\247\204\354\230\201/593. Valid Square" new file mode 100644 index 00000000..61aede4d --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/593. Valid Square" @@ -0,0 +1,34 @@ +/** + * @param {number[]} p1 + * @param {number[]} p2 + * @param {number[]} p3 + * @param {number[]} p4 + * @return {boolean} + */ +var validSquare = function(p1, p2, p3, p4) { + function distance(a,b){ + let dx = a[0] - b[0]; + let dy = a[1] - b[1]; + + return dx * dx + dy * dy; + } + + let arr = [ + distance(p1, p2), + distance(p1, p3), + distance(p1, p4), + distance(p2, p3), + distance(p2, p4), + distance(p3, p4) + ]; + + arr.sort((a, b) => a - b); + + return ( + arr[0] > 0 && + arr[0] === arr[1] && + arr[1] === arr[2] && + arr[2] === arr[3] && + arr[4] === arr[5] + ); +}; From fa32bc8b5745379d6bc10c46b00aaf17a6b95ae9 Mon Sep 17 00:00:00 2001 From: jihyup-byun Date: Sat, 10 Oct 2026 08:24:11 +0000 Subject: [PATCH 02/33] 593 --- .../v3/593. Valid Square.py" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/593. Valid Square.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/593. Valid Square.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/593. Valid Square.py" new file mode 100644 index 00000000..217cec0a --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/593. Valid Square.py" @@ -0,0 +1,33 @@ +''' +1. 아이디어 : + 4개 점 사이의 모든 순서쌍(12개) 거리를 유클리드 거리로 구해 딕셔너리에 카운트한다. + 정사각형이면 변 4개(양방향 8번)와 대각선 2개(양방향 4번)만 나오므로, + 거리별 개수를 정렬했을 때 [4, 8]이면 정사각형이다. + (int(length) != 0 조건으로 좌표가 겹치는 점(거리 0)은 카운트에서 제외한다.) +2. 시간복잡도 : + o(1) - 점이 항상 4개로 고정 +3. 자료구조/알고리즘 : + defaultdict(해시맵), 유클리드 거리 +''' + +from collections import defaultdict +import math + + +class Solution: + def validSquare(self, p1: list[int], p2: list[int], p3: list[int], p4: list[int]) -> bool: + lst = [p1, p2, p3, p4] + dic = defaultdict(int) + for i in range(4): + for j in range(4): + if i == j: + continue + x1, y1 = lst[i] + x2, y2 = lst[j] + length = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) + if int(length) != 0: + dic[length] += 1 + tmp = [i for i in dic.values()] + tmp.sort() + + return tmp == [4, 8] From da248fe280c786b9aa64add31434e08de7f185d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=9D=AC=EC=86=8C?= Date: Sun, 11 Oct 2026 22:43:30 +0900 Subject: [PATCH 03/33] 2350 --- .../2350. Shortest Impossible Sequence of Rolls.js" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "leetcode3/\352\271\200\355\235\254\354\206\214/2350. Shortest Impossible Sequence of Rolls.js" diff --git "a/leetcode3/\352\271\200\355\235\254\354\206\214/2350. Shortest Impossible Sequence of Rolls.js" "b/leetcode3/\352\271\200\355\235\254\354\206\214/2350. Shortest Impossible Sequence of Rolls.js" new file mode 100644 index 00000000..25619a90 --- /dev/null +++ "b/leetcode3/\352\271\200\355\235\254\354\206\214/2350. Shortest Impossible Sequence of Rolls.js" @@ -0,0 +1,8 @@ +/** + * @param {number[]} rolls + * @param {number} k + * @return {number} + */ +var shortestSequence = function(rolls, k) { + +}; \ No newline at end of file From c5950346778e7845465357bd699b1f573bc2b8bd Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Sun, 11 Oct 2026 23:36:36 +0900 Subject: [PATCH 04/33] Create 2350. Shortest Impossible Sequence of Rolls --- ...50. Shortest Impossible Sequence of Rolls" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/2350. Shortest Impossible Sequence of Rolls" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/2350. Shortest Impossible Sequence of Rolls" "b/leetcode3/\354\240\225\354\247\204\354\230\201/2350. Shortest Impossible Sequence of Rolls" new file mode 100644 index 00000000..f9c81254 --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/2350. Shortest Impossible Sequence of Rolls" @@ -0,0 +1,21 @@ +/** + * @param {number[]} rolls + * @param {number} k + * @return {number} + */ +var shortestSequence = function(rolls, k) { + let set = new Set(); + let count = 0; + + for (let i = 0; i < rolls.length; i++) { + set.add(rolls[i]); + + // 1 ~ k가 전부 한 번씩 모였으면 + if (set.size === k) { + count++; + set.clear(); + } + } + + return count + 1; +}; From 0eb35399848ef898bcfd6c9cf7c98434af848729 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Sun, 11 Oct 2026 17:12:38 +0900 Subject: [PATCH 05/33] Create 2350. Shortest Impossible Sequence of Rolls.py --- .../2350. Shortest Impossible Sequence of Rolls.py" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/2350. Shortest Impossible Sequence of Rolls.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/2350. Shortest Impossible Sequence of Rolls.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/2350. Shortest Impossible Sequence of Rolls.py" new file mode 100644 index 00000000..c44c618a --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/2350. Shortest Impossible Sequence of Rolls.py" @@ -0,0 +1,13 @@ +class Solution: + def shortestSequence(self, rolls: list[int], k: int) -> int: + seen = set() + ans = 1 + + for num in rolls: + seen.add(num) + + if len(seen) == k: + ans += 1 + seen.clear() + + return ans From a3b932b65cb363fa92134b9ee94f4e6f4c03b797 Mon Sep 17 00:00:00 2001 From: jihyup-byun Date: Sun, 11 Oct 2026 05:25:28 +0000 Subject: [PATCH 06/33] 2350 --- ... Shortest Impossible Sequence of Rolls.py" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/2350. Shortest Impossible Sequence of Rolls.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/2350. Shortest Impossible Sequence of Rolls.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/2350. Shortest Impossible Sequence of Rolls.py" new file mode 100644 index 00000000..07472c05 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/2350. Shortest Impossible Sequence of Rolls.py" @@ -0,0 +1,26 @@ +''' +실패 +''' +from collections import defaultdict + +class Solution: + def shortestSequence(self, rolls: list[int], k: int) -> int: + st = set() + for roll in rolls: + for s in list(st): + st.add(s+(roll,)) + st.add((roll,)) + + dic = defaultdict(int) + + for s in list(st): + dic[len(s)] += 1 + # print(dic[1]) + # print(dic[2]) + # print(dic[3]) + + num =1 + while True: + if not dic[num] == k ** num: + return num + num += 1 From 035bf86fc752b77810a725cf5f3d17b9f3ef8772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Mon, 12 Oct 2026 23:54:20 +0900 Subject: [PATCH 07/33] Create 4056. Number of Intersecting Interval Pairs I.java --- ...Number of Intersecting Interval Pairs I.java" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/4056. Number of Intersecting Interval Pairs I.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/4056. Number of Intersecting Interval Pairs I.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/4056. Number of Intersecting Interval Pairs I.java" new file mode 100644 index 00000000..f32aae7d --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/4056. Number of Intersecting Interval Pairs I.java" @@ -0,0 +1,16 @@ +class Solution { + public int countIntersections(int[][] intervals) { + int count = 0; + + for (int i = 0; i < intervals.length - 1; i++) { + for (int j = i + 1; j < intervals.length; j++) { + if (Math.max(intervals[i][0], intervals[j][0]) + <= Math.min(intervals[i][1], intervals[j][1])) { + count++; + } + } + } + + return count; + } +} From 734f97dc2b0d6abdb6fc7bc22dc54b1e6cc04896 Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Mon, 12 Oct 2026 23:09:53 +0900 Subject: [PATCH 08/33] Create 4056. Number of Intersecting Interval Pairs I --- ...56. Number of Intersecting Interval Pairs I" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/4056. Number of Intersecting Interval Pairs I" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/4056. Number of Intersecting Interval Pairs I" "b/leetcode3/\354\240\225\354\247\204\354\230\201/4056. Number of Intersecting Interval Pairs I" new file mode 100644 index 00000000..6b327100 --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/4056. Number of Intersecting Interval Pairs I" @@ -0,0 +1,17 @@ +/** + * @param {number[][]} intervals + * @return {number} + */ +var countIntersectingIntervals = function(intervals) { + let count = 0; + + for (let i = 0; i < intervals.length; i++){ + for (let j = i+1; j Date: Mon, 12 Oct 2026 10:00:51 +0000 Subject: [PATCH 09/33] 4056 --- ...umber of Intersecting Interval Pairs I.py" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/4056. Number of Intersecting Interval Pairs I.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4056. Number of Intersecting Interval Pairs I.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4056. Number of Intersecting Interval Pairs I.py" new file mode 100644 index 00000000..4c6048d3 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4056. Number of Intersecting Interval Pairs I.py" @@ -0,0 +1,30 @@ +''' +1. 아이디어 : +모든 (i, j) 쌍을 완전탐색하면서, 두 구간이 포함하는 정수 set을 각각 만들어 +교집합이 비어있지 않으면 교차로 카운트한다. +닫힌 구간이라 끝점(경계)만 공유해도 교차로 세어진다. +2. 시간복잡도 : +o(n^2 * m) # m = 구간 길이(end - start) +3. 자료구조/알고리즘 : +set(집합), 완전탐색 +''' + +class Solution: + def countIntersectingIntervals(self, intervals: list[list[int]]) -> int: + n = len(intervals) + ans = 0 + + for i in range(n-1): + for j in range(i+1,n): + st_a, st_b = set(), set() + a1,a2 = intervals[i] + b1,b2 = intervals[j] + for a in range(a1,a2+1): + st_a.add(a) + for b in range(b1,b2+1): + st_b.add(b) + # print(st_a, st_b) + if len(st_a & st_b) > 0: + ans +=1 + + return ans From a5c1fc4241ef4a74849574b559291558288dce47 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Mon, 12 Oct 2026 07:55:46 +0900 Subject: [PATCH 10/33] Create 4056. Number of Intersecting Interval Pairs I.py --- ...Number of Intersecting Interval Pairs I.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 leetcode3/4056. Number of Intersecting Interval Pairs I.py diff --git a/leetcode3/4056. Number of Intersecting Interval Pairs I.py b/leetcode3/4056. Number of Intersecting Interval Pairs I.py new file mode 100644 index 00000000..6bfac376 --- /dev/null +++ b/leetcode3/4056. Number of Intersecting Interval Pairs I.py @@ -0,0 +1,20 @@ +class Solution: + def countIntersectingIntervals(self, intervals: list[list[int]]) -> int: + + def check_intersect(point1, point2): + s1, e1 = point1 + s2, e2 = point2 + + if e1 < s2: + return False + if e2 < s1: + return False + return True + + n = len(intervals) + ans = 0 + for i in range(n): + for j in range(i+1, n): + if check_intersect(intervals[i], intervals[j]): + ans+=1 + return ans From 2245af7a5af9ae6191f79d8a33f38a3e08ef9a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=9D=AC=EC=86=8C?= Date: Tue, 13 Oct 2026 22:41:27 +0900 Subject: [PATCH 11/33] 4061 --- .../4061. Minimum Queen Moves to Reach Target.js" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "leetcode3/\352\271\200\355\235\254\354\206\214/4061. Minimum Queen Moves to Reach Target.js" diff --git "a/leetcode3/\352\271\200\355\235\254\354\206\214/4061. Minimum Queen Moves to Reach Target.js" "b/leetcode3/\352\271\200\355\235\254\354\206\214/4061. Minimum Queen Moves to Reach Target.js" new file mode 100644 index 00000000..44ce0e16 --- /dev/null +++ "b/leetcode3/\352\271\200\355\235\254\354\206\214/4061. Minimum Queen Moves to Reach Target.js" @@ -0,0 +1,14 @@ +/** + * @param {number[]} source + * @param {number[]} target + * @return {number} + */ + +var minQueenMoves = function(source, target) { + const rowDiff = Math.abs(source[0] - target[0]) + const colDiff = Math.abs(source[1] - target[1]) + + if (rowDiff === 0 && colDiff === 0) return 0; + if (rowDiff === colDiff || rowDiff === 0 || colDiff === 0) return 1; + return 2; +}; \ No newline at end of file From 4fe9879c926f39abb7293ae2181121cf16090843 Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:19:25 +0900 Subject: [PATCH 12/33] Implement minQueenMoves function for queen moves --- ...4061. Minimum Queen Moves to Reach Target" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/4061. Minimum Queen Moves to Reach Target" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/4061. Minimum Queen Moves to Reach Target" "b/leetcode3/\354\240\225\354\247\204\354\230\201/4061. Minimum Queen Moves to Reach Target" new file mode 100644 index 00000000..ca65831b --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/4061. Minimum Queen Moves to Reach Target" @@ -0,0 +1,19 @@ +/** + * @param {number[]} source + * @param {number[]} target + * @return {number} + */ +var minQueenMoves = function(source, target) { + // 8x8 + // 같은 좌표: 0 + // 대각선 라인, 같은 행, 열: 1 + // else: 2 + if (source[0] == target[0] && source[1] == target[1]) { + return 0; + } if ( + (Math.abs(source[0] - target[0]) == Math.abs(source[1] - target[1])) || (source[0] == target[0] && source[1] !== target[1]) || + (source[0] !== target[0] && source[1] == target[1]) + ) return 1; + + return 2; +}; From 626677927a56c65c187e7e77c18cd1a6928949a4 Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:41:33 +0900 Subject: [PATCH 13/33] Add carPooling function for trip capacity validation Implement carPooling function to check capacity. --- .../1094. Car Pooling" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/1094. Car Pooling" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/1094. Car Pooling" "b/leetcode3/\354\240\225\354\247\204\354\230\201/1094. Car Pooling" new file mode 100644 index 00000000..20ce939f --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/1094. Car Pooling" @@ -0,0 +1,20 @@ +/** + * @param {number[][]} trips + * @param {number} capacity + * @return {boolean} + */ +var carPooling = function(trips, capacity) { + // trips[i] = [numPassengers, from, to] + // nP 승객이 from에서 타서 to에서 내림 + let arr = new Array(1000).fill(0); + for (let i = 0; i Date: Tue, 13 Oct 2026 22:49:10 +0900 Subject: [PATCH 14/33] Update 1094. Car Pooling --- .../1094. Car Pooling" | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/1094. Car Pooling" "b/leetcode3/\354\240\225\354\247\204\354\230\201/1094. Car Pooling" index 20ce939f..b5d5aa0e 100644 --- "a/leetcode3/\354\240\225\354\247\204\354\230\201/1094. Car Pooling" +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/1094. Car Pooling" @@ -12,9 +12,16 @@ var carPooling = function(trips, capacity) { let from = trips[i][1]; let to = trips[i][2]; - arr[from] += np; - arr[to] -= np; + arr[from] += nP; + arr[to] -= nP; } - if (capacity) + let count = 0; + for (let j = 0; j < arr.length; j++){ + count += arr[j]; + if (count > capacity) { + return false; + } + } + return true; }; From 661ddbe8bce0d77de919e84721e5845811106e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:31:58 +0900 Subject: [PATCH 15/33] Create 4061. Minimum Queen Moves to Reach Target.java --- .../4061. Minimum Queen Moves to Reach Target.java" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/4061. Minimum Queen Moves to Reach Target.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/4061. Minimum Queen Moves to Reach Target.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/4061. Minimum Queen Moves to Reach Target.java" new file mode 100644 index 00000000..f2014048 --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/4061. Minimum Queen Moves to Reach Target.java" @@ -0,0 +1,12 @@ +// O(1) + +class Solution { + public int minQueenMoves(int[] source, int[] target) { + int x = Math.abs(source[0]-target[0]); + int y = Math.abs(source[1]-target[1]); + + if (x == 0 && y == 0) return 0; + else if (x == 0 || y == 0 || x == y) return 1; + else return 2; + } +} From ad86a2fd1878f1081e07ac0451dda93210168477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:32:44 +0900 Subject: [PATCH 16/33] Create 1094. Car Pooling.java --- .../1094. Car Pooling.java" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/1094. Car Pooling.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/1094. Car Pooling.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/1094. Car Pooling.java" new file mode 100644 index 00000000..ffff8e9b --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/1094. Car Pooling.java" @@ -0,0 +1,29 @@ +// 커스텀 정렬 +// O(n log n) + +class Solution { + public boolean carPooling(int[][] trips, int capacity) { + int[][] events = new int[trips.length*2][2]; + int i = 0; + for (int[] trip : trips) { + events[i] = new int[]{trip[1], trip[0]}; + i++; + events[i] = new int[]{trip[2], -trip[0]}; + i++; + } + + Arrays.sort(events, (a, b) -> { + // 승차 + 하차 - + // 위치 오름차순, 위치가 같으면 승객 오름차순 + if (a[0] == b[0]) return Integer.compare(a[1], b[1]); + return Integer.compare(a[0], b[0]); + }); + + int now = 0; + for (int[] event : events) { + now += event[1]; + if (now > capacity) return false; + } + return true; + } +} From 73967a75066c23ccbf3402116551c49c998c6a43 Mon Sep 17 00:00:00 2001 From: rimogsu Date: Tue, 13 Oct 2026 22:30:20 +0900 Subject: [PATCH 17/33] 1094,4061 --- .../v3/1094. Car Pooling.py" | 32 +++++++++ ...1. Minimum Queen Moves to Reach Target.py" | 69 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/1094. Car Pooling.py" create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/4061. Minimum Queen Moves to Reach Target.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1094. Car Pooling.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1094. Car Pooling.py" new file mode 100644 index 00000000..ea665b51 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1094. Car Pooling.py" @@ -0,0 +1,32 @@ +''' +1. 아이디어 : +1943. Describe the Painting.py +4개월전에 코딩테스트 참여했을 때 풀었던 문제인데 구조적으로 100% 동일한 문제임. +from을 +, to를 -로 둬서 해시의 누적합을 구하고, 여기서 누적합이 capacity를 초과하는지 확인하면 된다. + +2. 시간복잡도 : +o(n) + +3. 자료구조/알고리즘 : +- 배열(누적합), 해시맵(탑승/하차 위치 기록) +''' +from collections import defaultdict +class Solution: + def carPooling(self, trips: list[list[int]], capacity: int) -> bool: + dic = defaultdict(int) + + for n, _from, to in trips: + dic[_from] += n + dic[to] -= n + + print(dic) + + current = 0 + for i in [value for key, value in sorted(dic.items(), key=lambda x:x[0])]: + current += i + if current > capacity: + return False + + return True + + diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4061. Minimum Queen Moves to Reach Target.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4061. Minimum Queen Moves to Reach Target.py" new file mode 100644 index 00000000..a2ede354 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4061. Minimum Queen Moves to Reach Target.py" @@ -0,0 +1,69 @@ +''' +1. 아이디어 : +따져봤을 때 2번 안에 퀸이 다 갈 수 있음. +0번: src == target +1번: 퀸의 이동경로 (src!=target) +2번: 나머지 전부 + +2. 시간복잡도 : +o(1) - 경로만 바로 구하면 됨 + +3. 자료구조/알고리즘 : +''' +from collections import deque +class Solution: + def minQueenMoves(self, source: list[int], target: list[int]) -> int: + x1,y1 = tuple(source) + x2,y2 = tuple(target) + if x1 == x2 and y1 == y2: + return 0 + + st = set() + + for i in range(1,9): + st.add((x1,i)) + st.add((i,y1)) + + print(st) + + x = x1 + y = y1 + while 1 <= x < 9 and 1<= y < 9: + xtmp = x+1 + ytmp = y+1 + x = xtmp + y = ytmp + st.add((x,y)) + + x = x1 + y = y1 + while 1 <= x < 9 and 1<= y < 9: + xtmp = x-1 + ytmp = y-1 + x = xtmp + y = ytmp + st.add((x,y)) + x = x1 + y = y1 + + while 1 <= x < 9 and 1<= y < 9: + xtmp = x+1 + ytmp = y-1 + x = xtmp + y = ytmp + st.add((x,y)) + x = x1 + y = y1 + + while 1 <= x < 9 and 1<= y < 9: + xtmp = x-1 + ytmp = y+1 + x = xtmp + y = ytmp + st.add((x,y)) + + if (x2,y2) in st: + return 1 + else: + return 2 + From 99af5df4a34c5b8cbdb626f969dd3e66ca0986d4 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:17:29 +0900 Subject: [PATCH 18/33] =?UTF-8?q?Rename=20leetcode3/4056.=20Number=20of=20?= =?UTF-8?q?Intersecting=20Interval=20Pairs=20I.py=20to=20leetcode3/?= =?UTF-8?q?=EC=B5=9C=EC=9B=90=EC=A4=80/4056.=20Number=20of=20Intersecting?= =?UTF-8?q?=20Interval=20Pairs=20I.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../4056. Number of Intersecting Interval Pairs I.py" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename leetcode3/4056. Number of Intersecting Interval Pairs I.py => "leetcode3/\354\265\234\354\233\220\354\244\200/4056. Number of Intersecting Interval Pairs I.py" (100%) diff --git a/leetcode3/4056. Number of Intersecting Interval Pairs I.py "b/leetcode3/\354\265\234\354\233\220\354\244\200/4056. Number of Intersecting Interval Pairs I.py" similarity index 100% rename from leetcode3/4056. Number of Intersecting Interval Pairs I.py rename to "leetcode3/\354\265\234\354\233\220\354\244\200/4056. Number of Intersecting Interval Pairs I.py" From 71ffd3fd62f9e99ec983e78bae4d99a94d377a4e Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:19:23 +0900 Subject: [PATCH 19/33] Create 1094. Car Pooling.py --- .../1094. Car Pooling.py" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1094. Car Pooling.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1094. Car Pooling.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1094. Car Pooling.py" new file mode 100644 index 00000000..0016e6f6 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1094. Car Pooling.py" @@ -0,0 +1,33 @@ +# + +''' +1. 아이디어 : +미리 trip마다 탑승, 내리는 인원들을 구합니다. + +2. 시간복잡도 : + O(n+n) + +3. 자료구조/알고리즘 : +- + +''' +class Solution: + def carPooling(self, trips: list[list[int]], capacity: int) -> bool: + n = len(trips) + boarding = [0] * 1001 + curr = 0 + + for passengers, start, end in trips: + boarding[start] += passengers + boarding[end] -= passengers + + for i in range(1000): + curr += boarding[i] + if curr > capacity: + return False + + return True + + + + From d0f7cf8a73d47b26c579427876ed29973cb72609 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:19:41 +0900 Subject: [PATCH 20/33] Create 4061. Minimum Queen Moves to Reach Target.py --- ...1. Minimum Queen Moves to Reach Target.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/4061. Minimum Queen Moves to Reach Target.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/4061. Minimum Queen Moves to Reach Target.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/4061. Minimum Queen Moves to Reach Target.py" new file mode 100644 index 00000000..cd0dfade --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/4061. Minimum Queen Moves to Reach Target.py" @@ -0,0 +1,28 @@ +# + +''' +1. 아이디어 : +최대 2번 움직입니다 +0번: 같은 점 +1번: 같은 가로/세로/대각 +2번: 위 제외 나머지 + +2. 시간복잡도 : + O(1) + +3. 자료구조/알고리즘 : +- + +''' +class Solution: + def minQueenMoves(self, source: list[int], target: list[int]) -> int: + s1, s2 = source + e1, e2 = target + + if s1 == e1 and s2 ==e2: + return 0 + if s1 == e1 or s2 == e2 or abs(s1-e1) == abs(s2-e2): + return 1 + return 2 + + From cc44b2bdc9e24820be71721aae1a394bccd3ca58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=9D=AC=EC=86=8C?= Date: Wed, 14 Oct 2026 23:52:14 +0900 Subject: [PATCH 21/33] 4065 --- .../4065. Rearrange Array by Removing Distinct Values.js" | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 "leetcode3/\352\271\200\355\235\254\354\206\214/4065. Rearrange Array by Removing Distinct Values.js" diff --git "a/leetcode3/\352\271\200\355\235\254\354\206\214/4065. Rearrange Array by Removing Distinct Values.js" "b/leetcode3/\352\271\200\355\235\254\354\206\214/4065. Rearrange Array by Removing Distinct Values.js" new file mode 100644 index 00000000..5f4654cb --- /dev/null +++ "b/leetcode3/\352\271\200\355\235\254\354\206\214/4065. Rearrange Array by Removing Distinct Values.js" @@ -0,0 +1,7 @@ +/** + * @param {number[]} nums + * @return {number[]} + */ +var rearrangeArray = function(nums) { + +}; \ No newline at end of file From eb14db652e754a6f7d6920442d486354b48ae50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Wed, 14 Oct 2026 23:39:52 +0900 Subject: [PATCH 22/33] Create 4065. Rearrange Array by Removing Distinct Values.java --- ...ge Array by Removing Distinct Values.java" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/4065. Rearrange Array by Removing Distinct Values.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/4065. Rearrange Array by Removing Distinct Values.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/4065. Rearrange Array by Removing Distinct Values.java" new file mode 100644 index 00000000..f5b91bfe --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/4065. Rearrange Array by Removing Distinct Values.java" @@ -0,0 +1,24 @@ +class Solution { + public int[] rearrangeArray(int[] nums) { + int[] count = new int[101]; + int maxCount = 0; + + for (int num : nums) { + count[num]++; + maxCount = Math.max(maxCount, count[num]); + } + + int[] answer = new int[nums.length]; + int index = 0; + + for (int round = 1; round <= maxCount; round++) { + for (int value = 1; value <= 100; value++) { + if (count[value] >= round) { + answer[index++] = value; + } + } + } + + return answer; + } +} From 6bb9d8e779e2da2b59e7a431fd87cf18c308348b Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:08:25 +0000 Subject: [PATCH 23/33] Create 4065. Rearrange Array by Removing Distinct Values --- ...arrange Array by Removing Distinct Values" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/4065. Rearrange Array by Removing Distinct Values" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/4065. Rearrange Array by Removing Distinct Values" "b/leetcode3/\354\240\225\354\247\204\354\230\201/4065. Rearrange Array by Removing Distinct Values" new file mode 100644 index 00000000..19360325 --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/4065. Rearrange Array by Removing Distinct Values" @@ -0,0 +1,27 @@ +/** + * @param {number[]} nums + * @return {number[]} + */ +var rearrangeArray = function(nums) { + let ans = []; + + nums.sort((a,b)=>a-b); + + while (nums.length > 0){ + let set = new Set(); + let after = []; + + for (let i = 0; i Date: Wed, 14 Oct 2026 10:37:29 +0000 Subject: [PATCH 24/33] 4065 --- ...ange Array by Removing Distinct Values.py" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/4065. Rearrange Array by Removing Distinct Values.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4065. Rearrange Array by Removing Distinct Values.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4065. Rearrange Array by Removing Distinct Values.py" new file mode 100644 index 00000000..f618e221 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4065. Rearrange Array by Removing Distinct Values.py" @@ -0,0 +1,30 @@ +""" +1. 아이디어 : +- 매 라운드마다 nums에 남아있는 서로 다른 값들을 하나씩 제거해 오름차순으로 ans에 이어붙인다. +- Counter로 남은 값들의 개수를 세고, 등장하는 key마다 nums에서 하나씩 제거해 tmp에 모은 뒤 정렬해 ans에 extend. +- nums가 빌 때까지 반복. + +2. 시간복잡도 : +o(n^2) (최대값의 개수만큼 라운드 반복 * Counter/remove 비용) + +3. 자료구조/알고리즘 : +해시맵(Counter), 정렬, 시뮬레이션 + +""" + +from collections import Counter + + +class Solution: + def rearrangeArray(self, nums: list[int]) -> list[int]: + ans = [] + while nums: + tmp = [] + c = Counter(nums) + for key in c.keys(): + nums.remove(key) + tmp.append(key) + tmp.sort() + ans.extend(tmp) + + return ans From c110969ef16a5463b0eb2e90714a81c64c125da4 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Wed, 14 Oct 2026 11:01:31 +0900 Subject: [PATCH 25/33] Create 4065. Rearrange Array by Removing Distinct Values.py --- ...ange Array by Removing Distinct Values.py" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/4065. Rearrange Array by Removing Distinct Values.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/4065. Rearrange Array by Removing Distinct Values.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/4065. Rearrange Array by Removing Distinct Values.py" new file mode 100644 index 00000000..f57edc8f --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/4065. Rearrange Array by Removing Distinct Values.py" @@ -0,0 +1,26 @@ +class Solution: + def rearrangeArray(self, nums: list[int]) -> list[int]: + n = len(nums) + visited = set() + ans = [] + + while len(visited) != n: + + candids = set() + for i in range(n): + if i in visited: + continue + if nums[i] in candids: + continue + visited.add(i) + candids.add(nums[i]) + + temp = [] + for num in candids: + temp.append(num) + temp.sort() + for num in temp: + ans.append(num) + + return ans + From 14b391ddbbdba3c177145fb938b34b52eb284882 Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Thu, 15 Oct 2026 22:39:21 +0900 Subject: [PATCH 26/33] Create 2239. Find Closest Number to Zero --- .../2239. Find Closest Number to Zero" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/2239. Find Closest Number to Zero" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/2239. Find Closest Number to Zero" "b/leetcode3/\354\240\225\354\247\204\354\230\201/2239. Find Closest Number to Zero" new file mode 100644 index 00000000..d34679de --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/2239. Find Closest Number to Zero" @@ -0,0 +1,19 @@ +/** + * @param {number[]} nums + * @return {number} + */ +var findClosestNumber = function(nums) { + let abs = []; + + for (let i = 0; ia-b); // n log n + + if (nums.includes(abs[0])){ // n + return abs[0]; + } else { + return -abs[0]; + } +}; From 22d9809dfdb2d035ef804fa3af8745b768b0a84a Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Thu, 15 Oct 2026 22:40:30 +0900 Subject: [PATCH 27/33] Create 1124. Longest Well-Performing Interval --- .../1124. Longest Well-Performing Interval" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/1124. Longest Well-Performing Interval" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/1124. Longest Well-Performing Interval" "b/leetcode3/\354\240\225\354\247\204\354\230\201/1124. Longest Well-Performing Interval" new file mode 100644 index 00000000..120c4e9c --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/1124. Longest Well-Performing Interval" @@ -0,0 +1,25 @@ +/** + * @param {number[]} hours + * @return {number} + */ +var longestWPI = function(hours) { + let ans = 0; + + for (let i = 0; i < hours.length; i++) { + let sum = 0; + + for (let j = i; j < hours.length; j++) { + if (hours[j] > 8) { + sum += 1; + } else { + sum -= 1; + } + + if (sum > 0) { + ans = Math.max(ans, j - i + 1); + } + } + } + + return ans; +}; From e9cef927e84e608139552a2b4b7471e45be7a05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=9D=AC=EC=86=8C?= Date: Thu, 15 Oct 2026 22:41:38 +0900 Subject: [PATCH 28/33] 2239 --- .../\352\271\200\355\235\254\354\206\214/2239.js" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "leetcode3/\352\271\200\355\235\254\354\206\214/2239.js" diff --git "a/leetcode3/\352\271\200\355\235\254\354\206\214/2239.js" "b/leetcode3/\352\271\200\355\235\254\354\206\214/2239.js" new file mode 100644 index 00000000..215a423d --- /dev/null +++ "b/leetcode3/\352\271\200\355\235\254\354\206\214/2239.js" @@ -0,0 +1,15 @@ +/** + * @param {number[]} nums + * @return {number} + */ + +// 사이즈가 n인 nums 배열을 받을 때 nums 배열 안에서 0과 가장 가까운 값을 반환한다. 답이 여러개라면, 큰 값을 반환한다. + +var findClosestNumber = function(nums) { + let closets = nums[0]; + for (let i =0; i Date: Thu, 15 Oct 2026 22:40:33 +0900 Subject: [PATCH 29/33] Create 2239. Find Closest Number to Zero.java --- .../2239. Find Closest Number to Zero.java" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/2239. Find Closest Number to Zero.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/2239. Find Closest Number to Zero.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/2239. Find Closest Number to Zero.java" new file mode 100644 index 00000000..e76351f5 --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/2239. Find Closest Number to Zero.java" @@ -0,0 +1,14 @@ +// O(n) + +class Solution { + public int findClosestNumber(int[] nums) { + int min = Integer.MAX_VALUE; + for (int num : nums) { + if (Math.abs(min) > Math.abs(num)) min = num; + else if (Math.abs(min) == Math.abs(num)) { + if (min < num) min = num; + } + } + return min; + } +} From 8c5a2ac64f9c4774a6fd1e4be554df7d899630a6 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 15 Oct 2026 22:39:48 +0900 Subject: [PATCH 30/33] Create 2239. Find Closest Number to Zero.py --- .../2239. Find Closest Number to Zero.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/2239. Find Closest Number to Zero.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/2239. Find Closest Number to Zero.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/2239. Find Closest Number to Zero.py" new file mode 100644 index 00000000..3a0d011f --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/2239. Find Closest Number to Zero.py" @@ -0,0 +1,12 @@ +class Solution: + def findClosestNumber(self, nums: list[int]) -> int: + ans = -float('inf') + diff = float('inf') + for num in nums: + if abs(num) == diff: + ans = max(ans, num) + elif abs(num) < diff: + diff = abs(num) + ans = num + + return ans From 6c172090bc80fd00d44396d75eefd951f6cb401d Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 15 Oct 2026 22:40:09 +0900 Subject: [PATCH 31/33] Create 1124. Longest Well-Performing Interval.py --- ...1124. Longest Well-Performing Interval.py" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1124. Longest Well-Performing Interval.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1124. Longest Well-Performing Interval.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1124. Longest Well-Performing Interval.py" new file mode 100644 index 00000000..8160af0a --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1124. Longest Well-Performing Interval.py" @@ -0,0 +1,29 @@ +TLE + +class Solution: + def longestWPI(self, hours: list[int]) -> int: + n = len(hours) + + for i, hour in enumerate(hours): + hours[i] = 1 if hour>=9 else -1 + + prefix_sum = [0] * (n+1) + + for i in range(n): + prefix_sum[i+1] = prefix_sum[i] + hours[i] + + print(prefix_sum[1:]) + ans = 0 + + map = {} + + # for start in range(n): + # for end in range(start + 1, n+1): + # if prefix_sum[end] - prefix_sum[start] > 0: + # ans = max(ans, end - start) + + # for i, prefix in enumerate(prefix_sum): + + + return ans + From b5882cda9e6350ad7592de44943b9fb7e1a4e18e Mon Sep 17 00:00:00 2001 From: rimogsu Date: Thu, 15 Oct 2026 22:38:43 +0900 Subject: [PATCH 32/33] 1124,239 --- ...1124. Longest Well-Performing Interval.py" | 27 +++++++++++++++++++ .../v3/239. Find Closest Number to Zero.py" | 24 +++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/1124. Longest Well-Performing Interval.py" create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/239. Find Closest Number to Zero.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1124. Longest Well-Performing Interval.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1124. Longest Well-Performing Interval.py" new file mode 100644 index 00000000..141fb00f --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1124. Longest Well-Performing Interval.py" @@ -0,0 +1,27 @@ + +class Solution: + def run(self, hours): + lst = [1 if hour > 8 else -1 for hour in hours] + n = len(lst) + tmp = [0] * n + tmp[0] = max(lst[0],0) + for i in range(1,n): + tmp[i] = max(tmp[i-1]+lst[i],0) + print(tmp) + + streak = 0 + _max = -1 + for i in tmp: + # print(i, streak, _max) + if i != 0: + streak +=1 + else: + streak = 0 + + if streak > _max: + _max = streak + + return _max + + def longestWPI(self, hours: list[int]) -> int: + return max(self.run(hours), self.run(hours[::-1])) \ No newline at end of file diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/239. Find Closest Number to Zero.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/239. Find Closest Number to Zero.py" new file mode 100644 index 00000000..60482d97 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/239. Find Closest Number to Zero.py" @@ -0,0 +1,24 @@ +''' +1. 아이디어 : +절대값 작은거 찾고, 해당 num을 기록해둠. +그리고 같은 절대값이 나오면 num끼리 비교해서 더 큰거 선택 + +2. 시간복잡도 : +o(n) + +3. 자료구조/알고리즘 : +''' +class Solution: + def findClosestNumber(self, nums: list[int]) -> int: + _min, value = 9999999, 9999999 + + for num in nums: + print(num, _min,value) + if abs(num) < _min: + _min,value = abs(num), num + elif abs(num) == _min: + if num > value: + value = num + + return value + \ No newline at end of file From 401f7ca3e0df08b32c3e9c65fc846e6849ab1c92 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Fri, 16 Oct 2026 18:09:50 +0900 Subject: [PATCH 33/33] 4070. Minimum Rotations to Dial a Number I --- ...Minimum Rotations to Dial a Number I.java" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/4070. Minimum Rotations to Dial a Number I.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/4070. Minimum Rotations to Dial a Number I.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/4070. Minimum Rotations to Dial a Number I.java" new file mode 100644 index 00000000..f362fdc5 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/4070. Minimum Rotations to Dial a Number I.java" @@ -0,0 +1,36 @@ +/* + +1. 아이디어 : 다이얼 크기 10 -> 시계방향, 반시계방향 회전의 경우중 더 짧은것 선택 + + 경우의 수 (a->b) + 1. |a-b| + 2. 9 - |a-b| + +2. 시간복잡도 : O(s 문자열 길이) + +3. 자료구조/알고리즘 : 그리디 + + */ + +class Solution { + public int minRotations(String s) { + + int ans = 0; + int pos = 0; + + for(int i=0; i