题解 | #判断一个链表是否为回文结构#
判断一个链表是否为回文结构
http://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f
import java.util.*;
public class Solution {
public boolean isPail (ListNode head) {
// write code here
Stack <ListNode> st = new Stack<>();
int length = 0;
ListNode temp = head;
while(temp!=null){
st.push(temp);
length++;
temp=temp.next;
}
length = length/2;
for (int i=0;i<length;i++){
if(st.pop().val!=head.val){
return false;
}
head = head.next;
}
return true;
}
}