/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
#include <algorithm>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类 the head
* @return bool布尔型
*/
bool isPail(ListNode* head) {
// write code here
if(!head->next) return true;
vector<int> nums;
while(head) {
nums.push_back(head->val);
head = head->next;
}
vector<int> verse_nums = nums;
reverse(verse_nums.begin(), verse_nums.end());
for(int i = 0; i < nums.size(); i++) {
if(nums[i] != verse_nums[i]) return false;
}
return true;
}
};