其实特别简单,直接看代码吧
如果有重复元素
curr.next=curr.next.next;//相当于跳过重复节点
class Solution {
public ListNode deleteDuplicates(ListNode head) {
ListNode curr=head;
while(curr!=null&&curr.next!=null){
if(curr.val==curr.next.val) curr.next=curr.next.next;
else curr=curr.next;
}
return head;
}
}
网友评论