题目链接:https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof/
难度:简单
描述:
输入两个链表,找出它们的第一个公共节点。
题解
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution:def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:a, b = headA, headBwhile a != b:a = a.next if a else headBb = b.next if b else headAreturn a
