Skip to content

Commit a8bc92b

Browse files
Create Palindrome Linked List.py
1 parent b77af99 commit a8bc92b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution:
7+
def isPalindrome(self, head: ListNode) -> bool:
8+
stack = []
9+
ptr = head
10+
while ptr != None:
11+
stack.append(ptr.val)
12+
ptr = ptr.next
13+
while head != None:
14+
if head.val != stack.pop():
15+
return False
16+
head = head.next
17+
return True

0 commit comments

Comments
 (0)