Given a sorted linked list, delete all duplicates such that each element appear onlyonce.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3
public ListNode deleteDuplicates(ListNode head) {标签:head,slow,return,fast,next,链表,83,null,节点 From: https://www.cnblogs.com/MarkLeeBYR/p/17753399.html
if (head == null || head.next == null)
return head;
ListNode slow = head;
ListNode fast = head.next;
while (slow != null && fast != null) {
if (slow.val != fast.val) {
slow = fast;
fast = fast.next;
} else {
slow.next = fast.next;
fast = fast.next;
}
}
return head;
}