From f1d875e1838f3d78e5dfd5b778a5ec6078fac367 Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:41:09 +0900 Subject: [PATCH 1/2] Add minRotations function for dialing numbers Implement minRotations function to calculate minimum rotations needed to dial a number. --- ...0. Minimum Rotations to Dial a Number I 2" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/4070. Minimum Rotations to Dial a Number I 2" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/4070. Minimum Rotations to Dial a Number I 2" "b/leetcode3/\354\240\225\354\247\204\354\230\201/4070. Minimum Rotations to Dial a Number I 2" new file mode 100644 index 00000000..15c52127 --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/4070. Minimum Rotations to Dial a Number I 2" @@ -0,0 +1,33 @@ +/** + * @param {string} s + * @return {number} + */ +var minRotations = function(s) { + /* + 1 2 3 4 5 6 7 8 9 => 8회 + 1 0 9 => 2회 (10-2) + - 회전 방법 2개 + - 포인터 curr = 0 + - for문 돌면서 현재 숫자 - 다음 숫자 계산(최소값비교) + - next 로 포인터 이동 + + - curr : 현재 포인터 + - sum : 전체 횟수 + - lotate : 회전 횟수 + */ + + let sum = 0; + let curr = 0; + + for (let i = 0; i < s.length; i++) { + let next = Number(s[i]); + + let lotate = Math.abs(curr - next); + let minLotate = Math.min(lotate, 10-lotate); + sum += minLotate; + + curr = next; + } + + return sum; +}; From 6d8b9e49614f1f3b1af9d0dd7de3cdb6749a83ce Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:41:24 +0900 Subject: [PATCH 2/2] Add minCost function for component cost minimization Implement minCost function to minimize maximum component cost based on edges and desired components. --- .../3613. Minimize Maximum Component Cost" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/3613. Minimize Maximum Component Cost" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/3613. Minimize Maximum Component Cost" "b/leetcode3/\354\240\225\354\247\204\354\230\201/3613. Minimize Maximum Component Cost" new file mode 100644 index 00000000..118225f8 --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/3613. Minimize Maximum Component Cost" @@ -0,0 +1,36 @@ +/** + * @param {number} n + * @param {number[][]} edges + * @param {number} k + * @return {number} + */ +var minCost = function(n, edges, k) { + /* + edges[i] = [ui, vi, wi] + 간선 시작노드, 간선 끝 노드, 해당 간선 비용 + 제거 후 연결 요소 개수 k일 때의 cost 최소 + - 그리디 + - wi 기준으로 정렬 + - 연결 요소 : n-1 + - 다음 egdes와 연결이면 연결 요소-1 , 연결 요소 == k면 반복 종료 + - 그 때의 가중치 반환 + + - components : 연결요소 + - cost : 간선비용 + - + */ + + edges.sort((a, b) => a[2] - b[2]); + + let components = n; + let cost = 0; + let i = 0; + + while (components > k){ + if (edges[i][0]==edges[i+1][0] || ) + + components --; + + i++; + } +};