Leetcode_回文チェーンテーブル(探索一次アルゴリズム--python)
504 ワード
チェーンテーブルが返信チェーンテーブルであるかどうかを判断してください.
例1:
入力:1->2出力:false例2:
入力:1->2->2->1出力:true
例1:
入力:1->2出力:false例2:
入力:1->2->2->1出力:true
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def isPalindrome(self, head: ListNode) -> bool:
p=head
ans=[]
while p:
ans.append(p.val)
p=p.next
if ans==ans[::-1]:
return True
return False