Skip to content

Commit

Permalink
Time: 295 ms (49.62%) | Memory: 37 MB (26.49%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Mar 22, 2024
1 parent 0435e52 commit bba5e05
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 234-palindrome-linked-list/palindrome-linked-list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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:
list_vals = []
while head:
list_vals.append(head.val)
head = head.next

left, right = 0, len(list_vals) - 1
while left < right and list_vals[left] == list_vals[right]:
left += 1
right -= 1
return left >= right

0 comments on commit bba5e05

Please sign in to comment.