题解 | #牛群编号的回文顺序#
牛群编号的回文顺序
https://www.nowcoder.com/practice/e41428c80d48458fac60a35de44ec528
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
#include <vector>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return bool布尔型
*/
bool isPalindrome(ListNode* head) {
// 可以将链表中的数据保存到一个vector数组中,然后判断这个数组是否回文。
vector<int> v;
while(head){
v.push_back(head->val);
head=head->next;
}
for(int i=0,j=v.size()-1;i<j;i++,j--){
if(v[i]!=v[j]) return false;
}
return true;
}
};

