leetcode 234 (easy)

김준오·2021년 11월 22일
0

알고리즘

목록 보기
73/91
post-thumbnail

문제

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:
        arr = []
        
        while(1):
            arr.append(head.val)
            if not head.next: break
            head = head.next
            
        
        
        print(arr)
        return arr == arr[::-1]

링크드 리스트를 배열형식으로 변환 후 비교해주었다

profile
jooooon

0개의 댓글

Powered by GraphCDN, the GraphQL CDN