LeetCode数据结构集训难题求助

内容概览
我在LeetCode的数据结构集训中遇到了一个难题,我的代码虽然能够运行,但总是出错。经过多次尝试和询问GPT,仍然没有找到问题所在。希望有高手能帮忙看看我的代码,指出问题所在。
英雄哪里出来
2024-08-17 17:14
赞1
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...

英雄算法联盟

星球已运营 4 年零 211 天

累计超过  5700+  位成员加入

18小时前

最近更新

51000+

内容数

进入星球主页