HTMLify

LeetCode - Intersection of Two Linked Lists - Go
Views: 29 | Author: abh
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */

func getIntersectionNode(headA, headB *ListNode) *ListNode {
	thA := headA
	for thA != nil {
		thB := headB
		for thB != nil {
			if thB == thA {
				return thB
			}
			thB = thB.Next
		}
		thA = thA.Next
	}
	return nil
}

Comments