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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 287. Find the Duplicate Number (0) | 2024.03.24 |
---|---|
[Leetcode] 143. Reorder List (0) | 2024.03.23 |
[Leetcode] 206. Reverse Linked List (0) | 2024.03.21 |
[Leetcode] 1669. Merge In Between Linked Lists (0) | 2024.03.20 |
[Leetcode] 621. Task Scheduler (0) | 2024.03.19 |