switch1 [LeetCode] Intersection of Two Linked Lists (switch) 솔루션 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: p1 = headA p2 = headB while p1 != p2: if p1: p1 = p1.next else: p1 = headB if p2: p2 = p2.next else: p2 = headA return p1 while 문 조건을 p1 != p2 기준으로 두 node가 같은 경우 while문 중단한다. node가 다른 경우 .. 2021. 4. 2. 이전 1 다음