soulmachine / leetcode

LeetCode题解,151道题完整版。
BSD 3-Clause "New" or "Revised" License
11.3k stars 3.43k forks source link

fix a bug in "Remove Duplicates from Sorted List" #47

Closed windpls closed 8 years ago

windpls commented 9 years ago

In the original code, if the expression 'prev->val == cur->val' returns true, then prev->next will be updated and the memory 'cur' points to will be released. So, the cur = cur->next in 'for' is in fact illegal.

I fix this bug by just change cur = cur->next to cur=prev->next.

soulmachine commented 8 years ago

An exellent fix, thank you!