forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_2139.java
More file actions
24 lines (23 loc) · 659 Bytes
/
_2139.java
File metadata and controls
24 lines (23 loc) · 659 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.fishercoder.solutions;
public class _2139 {
public static class Solution1 {
public int minMoves(int target, int maxDoubles) {
int minMoves = 0;
while (target != 1) {
if (maxDoubles > 0) {
if (target % 2 == 0) {
target /= 2;
maxDoubles--;
} else {
target--;
}
} else {
minMoves += target - 1;
break;
}
minMoves++;
}
return minMoves;
}
}
}