본문 바로가기

IT/코딩테스트

[Leetcode] 234. Palindrome Linked List

728x90

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

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def isPalindrome(self, head: Optional[ListNode]) -> bool:
        vals = []

        node = head
        while node != None:
            vals.append(node.val)
            node = node.next

        for i in range(len(vals)):
            if vals[i] != vals[len(vals) - i - 1]:
                return False

        return True
728x90