Palindrome Linked List
password
URL
type
status
date
slug
summary
tags
category
icon
Using Stack to solve is easy.

Approach Recursive

And the problem use Stack can also use recursive to solve.
Think about,
Use self.cur to store the first node in the list, when the function check traverses to the end of the list, we can comparison the node on the head of the list by self.cur with the node on the tail (current node in current check)
Then we back from recursion, move self.cur to next node, and return comparison result to previous recursive call, in this turn the tail is the node previous of the tail in last turn.
 

© 糕糕 2021-2024.