/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
bool isPalindrome(ListNode* head) {
vector<int>obj;
while(head)
{
obj.push_back(head->val);
head=head->next;
}
int i=0;
int j=obj.size()-1;
while(i<j)
{
if(obj[i]!=obj[j])
{
return false;
}
i++;
j--;
}
return true;
}
};
LeetCode:234. 迴文鏈表
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.