/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
#include <bits/stdc++.h>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类 the head
* @return bool布尔型
*/
bool isPail(ListNode* head) {
ListNode* r = head;
vector<int> s;
while(r){
s.push_back(r->val);
r = r->next;
}
for(int i=0,j=s.size()-1;i<=j;i++,j--){
if(s[i]!=s[j]){
return false;
}
}
return true;
}
};
直接塞回数组里判断回文得了

京公网安备 11010502036488号