码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 234 Palindrome Linked List

时间:2015-07-10 10:49:54      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

Given a singly linked list, determine if it is a palindrome.

Follow up:
Could you do it in O(n) time and O(1) space?

 O(n)空间:存成数组后比较

class Solution:
    # @param {ListNode} head
    # @return {boolean}
    def isPalindrome(self, head):
        temp = []
        while head:
            temp.append(head.val)
            head = head.next
        return temp == temp[::-1]

 

Leetcode 234 Palindrome Linked List

标签:

原文地址:http://www.cnblogs.com/lilixu/p/4635010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!