class Solution {
public:
bool isPalindrome(ListNode* head) {
vector<int> res;
while (head) {
res.push_back(head->val);
head = head->next;
}
int i=0, j= res.size()-1;
while (i<=j) {
if(res[i]!=res[j]) return false;
i+=1; j-=1;
}
return true;
}
};
leetcode + 判断链表是不是回文的,先存到vector中然后就简单了
最新推荐文章于 2021-03-09 23:11:15 发布