Leetcode 234 回文链表 (每日一题 20210730)
生活随笔
收集整理的這篇文章主要介紹了
Leetcode 234 回文链表 (每日一题 20210730)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
請判斷一個鏈表是否為回文鏈表。示例 1:輸入: 1->2
輸出: false
示例 2:輸入: 1->2->2->1
輸出: true題目地址:https://leetcode-cn.com/problems/palindrome-linked-list/class Solution:def isPalindrome(self, head: ListNode) -> bool:res = []current = headwhile current:res.append(current.val)current = current.nextreturn res == res[::-1]
總結
以上是生活随笔為你收集整理的Leetcode 234 回文链表 (每日一题 20210730)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode 54 螺旋矩阵 (每日
- 下一篇: Leetcode 160 相交链表 (每