397 Integer Replacement
Last updated
Was this helpful?
Last updated
Was this helpful?
Given a positive integernand you can do operations as follow:
If n is even, replace n withn/2
.
If n is odd, you can replace n with eithern+ 1
orn- 1
.
What is the minimum number of replacements needed fornto become 1?
Example 1:
Example 2:
(1) BFS
BFS: 时间复杂度?, 空间复杂度?