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

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

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


全部评论

相关推荐

allin秋招的大菠萝很爱交友:后续,已拿offer ~查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务