版权声明:欢迎提问:[email protected] https://blog.csdn.net/include_heqile/article/details/81880584
https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/description/
我的解决方案:
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null) return null;
ListNode res= head;
while(head.next!=null) {
while(head.val==head.next.val) {
head.next=head.next.next;
if(head.next==null)
return res;
}
head=head.next;
}
return res;
}
}
在我提交的时候,我的代码是耗时最短的