bugl
Home
Learn
Patterns
Paths
Search
Premium
Auto
Home
Learn
Patterns
Paths
Medium
Greedy
LC 397
Integer Replacement
Given a positive integer n, you can apply one of the following operations:
If n is even, replace n with n /
2. If n is odd, replace n with either n + 1 or n -
Return the minimum number of operations needed for n to become 1.
Asked at 5 companies
Amazon
Baidu
Bloomberg
+2 more
Hints
1.
Think about which data structure fits best
2.
Consider the time complexity of your approach
3.
Look for patterns in the constraints
Start Puzzle
LeetCode