Remove sorts the list of duplicate nodes

The first node is a duplicate reservations

https://leetcode.com/problems/remove-duplicates-from-sorted-list/

This is easy to understand, encountered repeated put pointer to the next node is a duplicate.

The second delete all duplicate

https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/

This may be deleted due to the presence of the head node passed in the list, we first define a new head node.

A definition of two pointers, after a (last) continues to point to duplicate nodes, the nodes are not repeated when faced with the time, that is, $ last! = Last.next $, the next point before it needs a (pre) pointer after pointer next (because you want to delete all duplicate nodes, then repeat the last point to the current last node, so let $ pre.next = last.next $)

Guess you like

Origin www.cnblogs.com/ainsliaea/p/11484655.html