成环 dict 内存 判断
class Solution(object):
def hasCycle(self, head):
map = {}
while head:
if id(head) in map:
return True
map[id(head)] = True
head = head.next
return False
成环 dict 内存 判断
class Solution(object):
def hasCycle(self, head):
map = {}
while head:
if id(head) in map:
return True
map[id(head)] = True
head = head.next
return False