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

leetcode234

时间:2017-04-25 00:37:13      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:link   title   style   int   blog   tno   head   null   while   

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public bool IsPalindrome(ListNode head) {
        if (head == null)
            {
                return true;
            }
            else
            {
                Queue<int> Q = new Queue<int>();
                Stack<int> S = new Stack<int>();

                do
                {
                    Q.Enqueue(head.val);
                    S.Push(head.val);

                    head = head.next;
                }
                while (head != null);

                var len = S.Count;

                for (int i = 0; i < len; i++)
                {
                    var s = S.Pop();
                    var q = Q.Dequeue();
                    if (s != q)
                    {
                        return false;
                    }
                }
                return true;
            }
    }
}

https://leetcode.com/problems/palindrome-linked-list/#/description

leetcode234

标签:link   title   style   int   blog   tno   head   null   while   

原文地址:http://www.cnblogs.com/asenyang/p/6759451.html

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