一、题目
二、代码
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution
{
public:
bool isPalindrome(ListNode* head)
{
int i;
int length;
vector<int> re_vec;
ListNode* process_node=head;
while(process_node!=nullptr)
{
re_vec.push_back(process_node->val);
process_node=process_node->next;
}
length=re_vec.size();
for(i=0;i<length/2;i++)
{
if(re_vec[i]!=re_vec[length-1-i]) return 0;
}
return 1;
}
};