From 3977b20c6b06371c5ac8c99784605ea49c935713 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:33:14 +0900 Subject: [PATCH 1/2] Create 4070. Minimum Rotations to Dial a Number I.py --- .../4070. Minimum Rotations to Dial a Number I.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/4070. Minimum Rotations to Dial a Number I.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/4070. Minimum Rotations to Dial a Number I.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/4070. Minimum Rotations to Dial a Number I.py" new file mode 100644 index 00000000..3456d015 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/4070. Minimum Rotations to Dial a Number I.py" @@ -0,0 +1,12 @@ +class Solution: + def minRotations(self, s: str) -> int: + ans = 0 + curr = 0 + + for next in s: + num = int(next) + + diff = abs(curr-num) + ans += min(diff, 10-diff) + curr = num + return ans From ff72bbdefdc17b190be87feb4504a539d733b027 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:35:26 +0900 Subject: [PATCH 2/2] Create 3613. Minimize Maximum Component Cost.py --- .../3613. Minimize Maximum Component Cost.py" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/3613. Minimize Maximum Component Cost.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/3613. Minimize Maximum Component Cost.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/3613. Minimize Maximum Component Cost.py" new file mode 100644 index 00000000..2a0a57df --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/3613. Minimize Maximum Component Cost.py" @@ -0,0 +1,59 @@ +# + +''' +1. 아이디어 : +아무것도 연결하지 않은채로 시작. +edge를 가장 작은것부터 연결한다. +k개의 components일때까지 연결한다. (자연스럽게 가장 큰것들은 0이 됨) + +2. 시간복잡도 : + O(n) + +3. 자료구조/알고리즘 : +union-find + +''' +class Solution: + def minCost(self, n: int, edges: List[List[int]], k: int) -> int: + #union find + # edges.sort(key=lambda x: x[2]) + # for i in range(k-1): + # edges.pop() + # return edges[-1][2] if edges else 0 + + def find(x): + if par[x] != x: + par[x] = find(par[x]) + return par[x] + + def union(a, b): + a = find(a) + b = find(b) + + if a == b: + return False + + if size[a] < size[b]: + a, b = b, a + + par[b] = a + size[a] += size[b] + return True + + par = [i for i in range(n)] + size = [1] * n + + edges.sort(key=lambda x: x[2]) + + components = n + ans = 0 + + for u, v, w in edges: + if components<=k: + break + + if union(u, v): + components -= 1 + ans = w + + return ans if components <= k else -1