/**
* 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) {
stack<int> mystack;
int node_num = 0;
ListNode *tmp = head;
while(tmp != nullptr)
{
tmp = tmp->next;
node_num ++;
}
tmp = head;
for(int i=1 ; i<=node_num ;i++)
{
if(i<=node_num/2) mystack.push(tmp->val);
if(i>node_num/2+node_num%2)
{
if(tmp->val != mystack.top()) return false;
mystack.pop();
}
tmp = tmp->next;
}
return true;
}
};