首页 > 其他 > 详细

LeetCode(234):Palindrome Linked List

时间:2016-01-14 20:35:24      阅读:100      评论:0      收藏:0      [点我收藏+]

Palindrome Linked List:Given a singly linked list, determine if it is a palindrome.

题意:判断给定的一个链表中数,是否为回文。

思路:参考http://www.bkjia.com/ASPjc/1031678.html中的解法,采用递归的方式进行判断。

代码:

private ListNode lst;
    
    public boolean judge(ListNode head){
        if(head == null) return true;
        if(judge(head.next)==false) return false;
        if(lst.val!=head.val) {
            return false;
            
        }else{
            lst=lst.next;
            return true;
        }
    }
    
    
    public boolean isPalindrome(ListNode head) {
        if(head==null||head.next==null) return true;
        lst = head;
        return judge(head);
    }

LeetCode(234):Palindrome Linked List

原文:http://www.cnblogs.com/Lewisr/p/5131483.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!