파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 8. 23. 23:45

https://leetcode.com/problems/palindrome-linked-list/

 

Palindrome Linked List - 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 isPalindrome(self, head: Optional[ListNode]) -> bool:
        def check(head):
            if not head:
                return True
            
            res = check(head.next) and self.temp.val == head.val
            self.temp = self.temp.next
            return res
        self.temp = head
        return check(head)
반응형

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

Today's Challenge  (0) 2022.08.25
Today's Challenge  (0) 2022.08.24
Today's Challenge  (0) 2022.08.22
Today's Challenge  (0) 2022.08.21
Today's Challenge  (0) 2022.08.20
Comments