파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 6. 6. 23:45

https://leetcode.com/problems/intersection-of-two-linked-lists/

 

Intersection of Two Linked Lists - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

오예 Easy 난이도다 ㅎㅎ
근데 문제 설명이랑 풀이가 너무 상이해서.. 혼란이 왔음 ㅋㅋㅋ

class Solution:
    def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]:
        set_first = set()
        curr = headA
        
        while curr:
            set_first.add(curr)
            curr = curr.next
            
        curr = headB
        
        while curr:
            if curr in set_first:
                return curr
            curr = curr.next
            
        return None
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.06.08
Today's Challenge  (0) 2022.06.07
Today's Challenge  (0) 2022.06.05
Today's Challenge  (0) 2022.06.04
Today's Challenge  (0) 2022.06.03
Comments