请判断一个链表是否为回文链表。
示例 1:
输入: 1->2
输出: false
示例 2:
输入: 1->2->2->1
输出: true
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
bool isPalindrome(ListNode* head) {
ListNode* p=head;
vector<int>v;
while(p!=NULL){
int x=p->val;
v.push_back(x);
p=p->next;
}
int l=v.size();
for(int i=0;i<l;i++){
if(v[i]!=v[l-i-1])
return false;
}
return true;
}
};