题解 | #删除链表中重复的结点#
删除链表中重复的结点
http://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef
public class Solution {
public ListNode deleteDuplication(ListNode head) {
ListNode newhead = new ListNode(-1);
ListNode temp = newhead;
ListNode cur = head;
while(cur != null){
if(cur.next != null && cur.val == cur.next.val){
while(cur.next != null && cur.val == cur.next.val){
cur = cur.next;
}
cur = cur.next;
}
else{
temp.next = cur;
temp = temp.next;
cur = cur.next;
}
}
temp.next = null;
return newhead.next;
}
}