【LeetCode】160.相交链表

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time: 2019/3/26
# @Author: xfLi
# The file...

"""
问题分析:
与环形链表Ⅱ相似,两个指针追逐
"""

def getIntersectionNode(headA, headB):
    if not headA and not headB:
        return
    p, q = headA, headB
    while p != q:
        p = p.next if p else headB
        q = q.next if q else headA
    return p

猜你喜欢

转载自blog.csdn.net/qq_30159015/article/details/88831510