Given a sorted linked list, remove all duplicates from the linked list. For example, if the given linked list is 11->11->11->21->43->43->60, then the output should be 11->21->43->60.
- The list must be non-decreasing.
https://sauravhathi.github.io/remove-duplicates-from-sorted-list/
- Traverse the list from the head (or start) node.
- While traversing, compare each node with its next node.
- If the data of the next node is the same as the current node then delete the next node. Before we delete a node, we need to store the next pointer of the node.
- Otherwise, do nothing and move to the next node.
The time complexity of the above algorithm is O(n).
The space complexity of the above algorithm is O(1).