原题链接
解题思路:使用vector来存储链表,然后来检查其中每一个元素,是否组成回文
/*** 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> v;while(head){v.push_back(head->val);head = head->next;}// 判断是否回文for(int i=0; i<v.size()/2; ++i){if(v[i] != v[v.size()-1-i]){return false;}}return true;}
};