Embrace 提问:英雄哥,你好,这是数据结构集训中的一道题:<e type="web" href="https%3A%2F%2Fleetcode.cn%2F..." title=".%20%20-%20%E5%8A%9B%E6%89%A3%EF%BC%88LeetCode%EF%BC%89" />「加入星球后可见」
以下是我的代码:
class Solution {
public:
ListNode* removeDuplicateNodes(ListNode* head) {
if( !head || !head->next ){
return head;
}
ListNode* temp;
ListNode* curr = head;
while( curr->next ){
ListNode* temp_back = curr;
temp = curr->next;
while( temp ){
if( temp->val == curr->val ){
temp = temp->next;
delete temp_back->next;
temp_back->next =temp;
}
else{
temp_back = temp;
temp = temp->next;
}
}
curr = curr->next;
}
return head;
}
};
我知道我这个用temp_back的方法可能很奇怪,很复杂,但是这是我当时的第一想法,我很想知道这个代码错误是在哪里,问了gpt也没有问出个所以然,请英雄哥花些时间阅读一下这个代码,谢谢英雄哥!
第 9 行改成: while( curr && cur...