class Solution {
public:
bool isPail(ListNode* head) {
stack<ListNode*> s;//利用栈先进后出
ListNode* cur=head;
while(cur){
s.push(cur);
cur=cur->next;
}
while(!s.empty()){
if(s.top()->val==head->val){
s.pop();
head=head->next;
}
else
return false;
}
return true;
}
};
【牛客网】BM13 判断一个链表是否为回文结构
最新推荐文章于 2024-06-21 18:05:33 发布