class Solution(object):
def circularArrayLoop(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
for i in range(0,len(nums)):
k=[]
xiabiao=i
k.append(xiabiao)
while len(k)<=len(nums):
xiabiao=(xiabiao+nums[xiabiao])%len(nums)
if len(k)>1 and xiabiao in k : return True
# print xiabiao,nums[xiabiao],nums[k[0]]
if (nums[xiabiao]>0 and nums[k[0]]>0) or (nums[xiabiao]<0 and nums[k[0]]<0):
if nums[xiabiao]%len(nums)==0 :
break
else:
k.append(xiabiao)
else:
break
# print k
return False
网友评论