8.27 - hard - 108
2017-08-28 本文已影响0人
健时总向乱中忙
600. Non-negative Integers without Consecutive Ones
这题的递推公式实在是太tricky了。。。。
class Solution(object):
def findIntegers(self, num):
"""
:type num: int
:rtype: int
"""
x, y = 1, 2
res = 0
num += 1
while num:
if num & 1 and num & 2:
res = 0
res += x * (num & 1)
num >>= 1
x, y = y, x + y
return res