题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n)$
blablabla
时间复杂度
参考文献
Java 代码
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
ListNode dummy = new ListNode(-1);
dummy.next = head;
ListNode cur = dummy.next;
ListNode prev = dummy;
while(cur != null){
if(cur.next != null && cur.val == cur.next.val){
while(cur.next != null && cur.val == cur.next.val){
cur = cur.next;
}
prev.next = cur.next;
}else{
prev = prev.next;
}
cur = cur.next;
}
return dummy.next;
}
}