/** * Definition for ListNode * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { /** * @param head: head is the head of the linked list * @return: head of linked list */ public ListNode deleteDuplicates(ListNode head) { if(head==null||head.next==null){ return head; } ListNode p=head; while(p.next!=null){ if(p.val!=p.next.val){ p=p.next; } else { p.next=p.next.next; } } return head; } }