类似于running sum的思路,就是a^b^a=b
然后就是找规律了
def helper(x):
n=x%8
if n==0 or n==1: return x
if n==2 or n==3: return 2
if n==4 or n==5: return x+2
return 0
def xorSequence(l, r):
return helper(l-1)^helper(r)
类似于running sum的思路,就是a^b^a=b
然后就是找规律了
def helper(x):
n=x%8
if n==0 or n==1: return x
if n==2 or n==3: return 2
if n==4 or n==5: return x+2
return 0
def xorSequence(l, r):
return helper(l-1)^helper(r)