相同的时候,prev指针不动,cur.next = cur.next.next

不相同的时候, prev跟cur指针同时更新。

 

 1 /**
 2  * class ListNode {
 3  *   public int value;
 4  *   public ListNode next;
 5  *   public ListNode(int value) {
 6  *     this.value = value;
 7  *     next = null;
 8  *   }
 9  * }
10  */
11 public class Solution {
12   public ListNode removeDup(ListNode head) {
13     // Write your solution here
14     if (head == null) {
15          return head; 
16     }
17     ListNode prev = head, cur = head;
18     while (cur.next != null) {
19         if (cur.value == cur.next.value) {
20           cur.next = cur.next.next; 
21       } else {
22         prev = cur;
23            cur = cur.next;
24       }
25     }
26     return head;
27   }
28 }

 

posted on 2018-03-02 08:48  mayinmiao  阅读(104)  评论(0编辑  收藏  举报