【专题】 反向思考
Author: azl397985856Created Nov 14, 2022Updated Nov 15, 2022
记录反向思考的题目。比如: 991. 坏了的计算器
class Solution:
def brokenCalc(self, startValue: int, target: int) -> int:
ans = 0
while startValue != target:
if target < startValue: return ans + startValue - target
if target & 1:
target += 1
else:
target = target // 2
ans += 1
return ans
Source: azl397985856/leetcode