class Solution {
public:
ListNode* swapPairs(ListNode* head) {
if(head==NULL||head->next==NULL) //为什么这里去掉后面对 head->next 的判断提交会报错啊
return head;
ListNode* temp=head->next;
head->next=swapPairs(head->next->next);
temp->next=head;
return temp;
}
};
错误如下:
Runtime Error Message: Line 16: Char 29: runtime error: member access within null pointer of type 'struct ListNode' (solution.cpp)
判断head是空的话,直接return不就行了吗,感觉不用再判断head->next了吧