#### 平平无奇 空间O(n)复杂度

``````/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
vector<int> res;
{
}

for(int i = 0;i < res.size()/2;i++)
{
if(res[i] != res[res.size() - 1 - i]) return false;
}

return true;
}
};``````

``````执行结果：通过  显示详情

#### 递归

``````/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
private:
bool recursivelyCheck(ListNode * currentNode) {
if(currentNode)
{
if(!recursivelyCheck(currentNode->next))
return false;

if(currentNode->val != positive_pointer->val)
return false;

positive_pointer = positive_pointer->next;
}

return true;
}
public:
}
private:
ListNode* positive_pointer;
};``````

#### O(1)空间复杂度

O(1)空间复杂度，需要将后半段逆序，然后进行比较，这种方法的弊端是修改了链表。

``````/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
return true;
ListNode *second_start = reverseList(first_end->next);
while(second_start)
{
return false;
second_start = second_start->next;
}

return true;
}

private:
ListNode* prev = nullptr;
while (curr != nullptr) {
ListNode* next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}