public class Solution
{
public ListNode deleteDuplicates(ListNode head)
{
if(head==null||head.next==null)
{
return head;
}
ListNode temp_head=head;
//遍历到倒数第二个节点,因为删除是操作.next的
while(temp_head.next!=null)
{
int curr_val=temp_head.val;
int next_val=temp_head.next.val;
while(curr_val==next_val)
{
//2,2,2,null ->2,2,null
temp_head.next=temp_head.next.next;
//在对下个元素的值进行更新前,现要判断他是不是空的说
if(temp_head.next==null)
{
return head;
// break; 此处用break为啥就不通过呢
}
//对下个元素的值进行更新
next_val=temp_head.next.val;
}
temp_head=temp_head.next;
}
return head;
}
}