力扣 234. 回文链表

前置

1
2
3
4
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next

递归

1
2
3
4
5
6
7
8
def isPalindrome(head):
def digui(s, e):
if not e: return s, True
s, ret = digui(s, e.next)
ret = ret and s.val == e.val
return s.next, ret
_, ret = digui(head, head)
return ret
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信