234. Palindrome Linked List、
解析
solution1:没有想出space(1)的方法( __ )
遍历一遍链表,把值放在string.接下来就是常规的回文字符串判断了。
class Solution {
public:
bool isPalindrome(ListNode* head) {
std::string input;
while(head != NULL){
input+=(char)(head->val);
head=head->next;
}
int size = input.size();
for(int i=0; i<size/2 ;i++){
if(input.at(i) != input.at(size-1-i))
return false;
}
return true;
}
};