标签: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
标签:link title style int blog tno head null while
原文地址:http://www.cnblogs.com/asenyang/p/6759451.html