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.
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.