题解 | #判断一个链表是否为回文结构#

判断一个链表是否为回文结构

http://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f

思路:
1.将链表转成列表处理
2.使用双指针大法
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

#
# 
# @param head ListNode类 the head
# @return bool布尔型
#
class Solution:
    def isPail(self , head ):
        # write code here
        nums=[]
        p=head
        #将链表变成列表
        while p:
            nums.append(p.val)
            p=p.next
        n=len(nums)
        l=0
        r=n-1
        while l<r:
            if nums[l]!=nums[r]:
                return False
            l+=1
            r-=1
        return True


全部评论

相关推荐

03-29 12:10
门头沟学院 C++
挣K存W养DOG:散漫消极者淘汰,一眼坑爹。实习几个月转正的时候说你加班太少,能力还行态度不够积极裁了,马上老实。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务