Leetcode83. Remove Duplicates from Sorted List
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null) return null;
ListNode pre = head,p = head.next;
while(p!=null){
if(p.val==pre.val){
pre.next = p.next;
}else{
pre = pre.next;
}
p = pre.next;
}
return head;
}
}
Runtime: 1 ms, faster than 21.21% of Java online submissions for Remove Duplicates from Sorted List.
Memory Usage: 37.8 MB, less than 21.98% of Java online submissions for Remove Duplicates from Sorted List.

浙公网安备 33010602011771号