Skip to content

Commit 9d49c97

Browse files
authored
Create broken-calculator.py
1 parent 2b53594 commit 9d49c97

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/broken-calculator.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(logn)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def brokenCalc(self, X, Y):
6+
"""
7+
:type X: int
8+
:type Y: int
9+
:rtype: int
10+
"""
11+
result = 0
12+
while X < Y:
13+
if Y%2:
14+
Y += 1
15+
else:
16+
Y /= 2
17+
result += 1
18+
return result + X-Y

0 commit comments

Comments
 (0)