- 연결리스트의 요소들을 res 배열에 넣어줌.
- res배열을 문자열로 바꿔준 후, slicing을 통해 palindrome 성립 여부 확인함.
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
def isPalindrome(self, head: Optional[ListNode]) -> bool:
res = []
while head != None :
res.append(head.val)
head = head.next
tmp = ''.join(list(map(str, res)))
if tmp == tmp[::-1] :
return True
return False