0
点赞
收藏
分享

微信扫一扫

C语言scanf( ) 函数的格式控制包括哪些?

Python芸芸 2024-06-07 阅读 8

文章目录

题目描述

思路

复杂度

时间复杂度:

空间复杂度:

Code

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
public class Solution {
    /**
     * Find intersecting nodes of intersecting linked lists
     *
     * @param headA The head node of linked list A
     * @param headB The head node of linked list B
     * @return ListNode
     */
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode p1 = headA;
        ListNode p2 = headB;
        while (p1 != p2) {
            if (p1 == null) {
                p1 = headB;
            } else {
                p1 = p1.next;
            }
            if (p2 == null) {
                p2 = headA;
            } else {
                p2 = p2.next;
            }
        }
        return p1;
    }
}

举报

相关推荐

0 条评论