/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head == null || head.next == null){
return head;
}
ListNode dummy = new ListNode(Integer.MIN_VALUE);
dummy.next = head;
ListNode pre = dummy, cur = dummy.next;
while(cur != null){
if(pre.val == cur.val){
pre.next = cur.next;
}else{
pre = pre.next;
}
cur = cur.next;
}
return dummy.next;
}
}
[LeetCode] 83. Remove Duplicates from Sorted List
最新推荐文章于 2022-10-07 16:39:37 发布