p0397

package
v0.0.0-...-4302f07 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2019 License: MIT Imports: 0 Imported by: 0

README

以二进制的角度看,偶数/2相当于消掉末尾的0,奇数+-1相当于将末尾的1变0,同时+1会产生进位。 相当于将二进制数不断消去末尾只剩1的最少步数。

对于末尾0来说,直接消去,只用1步

对于末尾1来说,需要先变成0再消去,需要2步

而+1产生的进位会使得前面的若干位反转,显然1反转成0的步数会比0反转成1更优

所以只需判断倒数第二位是否为1

注意3(11)这个特殊情况

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL