力扣第九天——环形链表

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def hasCycle(self, head: ListNode) -> bool:
        pre=head
        if head==None or head.next==None:
            return False
        l1=head
        l2=head.next
        while (l1!=l2):
            if l2==None or l2.next==None:
                return False
            else:
                l1=l1.next
                l2=l2.next.next
        return True
发布了11 篇原创文章 · 获赞 0 · 访问量 201

猜你喜欢

转载自blog.csdn.net/yifeng113/article/details/104746483