import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* }
*/
public class Solution {
/**
*
* @param head ListNode类
* @return ListNode类
*/
public ListNode deleteDuplicates (ListNode head) {
// write code here
if (head == null || head.next == null) {
return head;
}
ListNode tail = head;
ListNode cur = head.next;
while (cur != null) {
if (cur.val != tail.val) {
tail.next = cur;
tail = cur;
}
cur = cur.next;
}
tail.next = null;
return head;
}
}

京公网安备 11010502036488号