Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Autosaved

...

逻辑上分析「A+B」和「B+A」两条链表,找到公共节点https://singee.atlassian.net/wiki/spaces/MAIN/pages/49316106/Week+41+2024#LC-160.-Intersection-of-Two-Linked-Lists-%E7%9B%B8%E4%BA%A4%E9%93%BE%E8%A1%A8%EF%BC%88%E5%88%A4%E6%96%AD%E4%B8%A4%E4%B8%AA%E9%93%BE%E8%A1%A8%E6%98%AF%E5%90%A6%E7%9B%B8%E4%BA%A4%EF%BC%89

Code Block
languagego
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func getIntersectionNode(headA, headB *ListNode) *ListNode {
    p1 := headA
    p2 := headB
    
    for p1 != p2 {
        if p1 == nil {
            p1 = headB
        } else {
             p1 = p1.Next
        }
        
        if p2 == nil {
            p2 = headA
        } else {
            p2 = p2.Next
        }
    }
    
    return p1
}

LC 82. Remove Duplicates from Sorted List II 删除排序链表中的重复元素 II

https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/