# Leetcode 83. Remove Duplicates from Sorted List (C語言) - 題目 Given a sorted linked list, delete all duplicates such that each element appear only once. - 範例 Input: 1->1->2->3->3 Output: 1->2->3 ```c= struct ListNode* deleteDuplicates(struct ListNode* head){ if(head){ struct ListNode *current=head,*releasenode; while(current->next){ if(current->val==current->next->val){ releasenode=current->next; current->next=releasenode->next; free(releasenode); } else{ current=current->next; } } } return head; } ``` 思路:linklist去除多餘元素,因為是sorted list故從頭開始找,若現點與下點值相同, 則將現點指向下下點,free下點。 ``` a b c 1 -> 1 -> 3 發現值相同(a點=b點),將a點指向c點,釋放b點 a c 1 -> 3 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up