Skip to content

【专题】 反向思考 #572

Open
Open
@azl397985856

Description

@azl397985856

记录反向思考的题目。比如: 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions