From 24f2413cb8932151f4380aec50debfbdd46354c2 Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:52:43 +0900 Subject: [PATCH] Create 4070. Minimum Rotations to Dial a Number I --- ...070. Minimum Rotations to Dial a Number I" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/4070. Minimum Rotations to Dial a Number I" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/4070. Minimum Rotations to Dial a Number I" "b/leetcode3/\354\240\225\354\247\204\354\230\201/4070. Minimum Rotations to Dial a Number I" new file mode 100644 index 00000000..9973e020 --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/4070. Minimum Rotations to Dial a Number I" @@ -0,0 +1,24 @@ +/** + * @param {string} s + * @return {number} + */ +var minRotations = function(s) { + let ans = 0; + let curr = 0; + + for (let i = 0; i < s.length; i++) { + let next = Number(s[i]); + + let diff = Math.abs(curr - next); + + if (diff <= 5) { + ans += diff; + } else { + ans += 10 - diff; + } + + curr = next; + } + + return ans; +};