Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created October 18, 2020 14:49
Show Gist options
  • Save inspirit941/de56e97b739d349d104c2f95058ab52d to your computer and use it in GitHub Desktop.
Save inspirit941/de56e97b739d349d104c2f95058ab52d to your computer and use it in GitHub Desktop.
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
from collections import deque
class Solution:
def isPalindrome(self, head: ListNode) -> bool:
if not head: return True
# deque를 활용한 풀이
# 링크드 리스트 데이터를 deque에 저장.
queue: Deque = deque()
node = head
while node:
queue.append(node.val)
node = node.next
while len(queue) > 1:
if queue.popleft() != queue.pop():
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment