Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 96a46d8

Browse files
Create Solution.py
1 parent b29bd1a commit 96a46d8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎Palindrome Linked List/Solution.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def insert_list(self, head):
3+
stack = []
4+
while(head):
5+
stack.append(head.val)
6+
head = head.next
7+
return stack
8+
9+
def isPalindrome(self, head: ListNode) -> bool:
10+
if head == None:
11+
return True
12+
reverse_stack = self.insert_list(head)
13+
while(head):
14+
if(head.val == reverse_stack.pop()):
15+
head = head.next
16+
else:
17+
return False
18+
return True

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /