题目链接:https://leetcode-cn.com/problems/palindrome-linked-list-lcci/
题目如下:
/**
* 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) {
vector<int> vtr;
while(head!=NULL){
vtr.push_back(head->val);
head=head->next;
}
for(int i=0;i<vtr.size()/2;i++){
if(vtr[i]!=vtr[vtr.size()-i-1]) return false;
}
return true;
}
};