题解 | #判断一个链表是否为回文结构#
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类 the head
* @return bool布尔型
*/
bool isPail(ListNode* head) {
// write code here
vector<int> t;
int i = 0;
while(head != nullptr){
t.push_back(head->val);
head = head->next;
i++;
}
int k = i/2;
for(int j=0;j<k;j++){
if(t[j] != t[i-1-j]) return false;
}
return true;
}
};

