今際の国の呵呵君
Tuesday, October 31, 2017
[LeetCode]Power of Two
位运算的题,Power of two转化成2进制的话只可能是某一位是1其余为0,我们只需要用n&(n - 1)检测即可,这个运算可以每次消去n的最低为1的位,我们只需检测运算后结果是否为0即可,O(1)时间复杂度,代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment