Broken Calculator LeetCode solution in Python

1
class Solution(object):
2
def brokenCalc(self, startValue, target):
3
"""
4
:type startValue: int
5
:type target: int
6
:rtype: int
7
"""
8
res = 0
9
while target > startValue:
10
res += 1
11
if target % 2:
12
target += 1
13
else:
14
target //= 2
15
return res + startValue - target

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0