Minimum Moves to Reach Target Score LeetCode solution in Python

1
# Runtime: 58 ms (Top 30.40%) | Memory: 14 MB (Top 14.20%)
2
class Solution:
3
def minMoves(self, target: int, maxDoubles: int) -> int:
4
c = 0
5
while maxDoubles > 0 and target > 1:
6
c += target % 2
7
target //= 2
8
c += 1
9
maxDoubles -= 1
10
return c + target - 1

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0