力扣160-JS相交链表

https://leetcode.cn/problems/intersection-of-two-linked-lists/description/?envType=study-plan-v2&envId=top-100-liked

力扣160-JS相交链表

力扣160-JS相交链表

力扣160-JS相交链表

/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */
var getIntersectionNode = function (headA, headB) {
  let curA = headA
  let curB = headB

  while (curA !== curB) {
    curA = curA === null ? headB : curA.next
    curB = curB === null ? headA : curB.next
  }

  return curA

};

力扣160-JS相交链表

原创文章,作者:czhdawn,如若转载,请注明出处:https://www.czhdawn.cn/archives/4906

(0)
czhdawn的头像czhdawn
上一篇 2025年8月2日 10:52
下一篇 2025年8月4日 17:20

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注