Skip to content

Commit 9fbb40a

Browse files
add 4070
1 parent 60e982c commit 9fbb40a

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

  • paginated_contents/algorithms/5th_thousand
  • src/main/java/com/fishercoder/solutions/fifththousand

‎paginated_contents/algorithms/5th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|------------|----------------------------------------------------------------------
3+
| 4070 | [Minimum Rotations to Dial a Number I](https://leetcode.com/problems/minimum-rotations-to-dial-a-number-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4070.java) | | Easy |
34
| 4065 | [Rearrange Array by Removing Distinct Values](https://leetcode.com/problems/rearrange-array-by-removing-distinct-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4065.java) | | Easy |
45
| 4061 | [Minimum Queen Moves to Reach Target](https://leetcode.com/problems/minimum-queen-moves-to-reach-target/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4061.java) | | Easy |
56
| 4056 | [Number of Intersecting Interval Pairs I](https://leetcode.com/problems/number-of-intersecting-interval-pairs-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4056.java) | | Easy |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions.fifththousand;
2+
3+
public class _4070 {
4+
public static class Solution1 {
5+
public int minRotations(String s) {
6+
int r = 0;
7+
for (int i = -1; i < s.length() - 1; i++) {
8+
int from = i == -1 ? 0 : Character.getNumericValue(s.charAt(i));
9+
int to = Character.getNumericValue(s.charAt(i + 1));
10+
int bigger = 0;
11+
int smaller = 0;
12+
if (from > to) {
13+
bigger = from;
14+
smaller = to;
15+
} else if (from < to) {
16+
bigger = to;
17+
smaller = from;
18+
}
19+
r += Math.min(bigger - smaller, Math.abs(10 - bigger + smaller));
20+
}
21+
return r;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)