@@ -0,0 +1,949 @@
+package com.yan.leetcode;%0A%0Aimport org.junit.Test;%0A%0Apublic class RemoveDuplicatesFromSortedList %7B%0A%0A%09@Test%0A%09public void test() %7B%0A%09%09ListNode head = new ListNode(1);%0A%09%09head.next = new ListNode(1);%0A%09%09// head.next.next = new ListNode(2);%0A%09%09System.out.println(deleteDuplicates2(head));%0A%09%7D%0A%0A%09public ListNode deleteDuplicates(ListNode head) %7B%0A%09%09if (head == null %7C%7C head.next == null) %7B%0A%09%09%09return head;%0A%09%09%7D%0A%09%09ListNode index = head;%0A%09%09while (index.next != null) %7B%0A%09%09%09if (index.next.val == index.val) %7B%0A%09%09%09%09index.next = index.next.next;%0A%09%09%09%7D else %7B%0A%09%09%09%09index = index.next;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return head;%0A%09%7D%0A%0A%09public ListNode deleteDuplicates2(ListNode head) %7B%0A%09%09if (head == null) %7B%0A%09%09%09return head;%0A%09%09%7D%0A%09%09ListNode newHead = new ListNode(Integer.MAX_VALUE);%0A%09%09ListNode index = newHead;%0A%09%09while (head != null) %7B%0A%09%09%09if (head.val != index.val) %7B%0A%09%09%09%09index.next = head;%0A%09%09%09%09index = index.next;%0A%09%09%09%7D%0A%09%09%09head = head.next;%0A%09%09%7D%0A%09%09index.next = null;%0A%09%09return newHead.next;%0A%09%7D%0A%0A%7D%0A

remove duplicates from sorted list