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; +};