1. /**
    2. * @Description 一道中等题,还是要注意设置虚拟头结点,然后考虑循环不变量
    3. * @Date 2022/1/19 10:33 下午
    4. * @Author wuqichuan@zuoyebang.com
    5. **/
    6. public class Solution {
    7. public ListNode deleteDuplicates(ListNode head) {
    8. ListNode dummyHead = new ListNode();
    9. dummyHead.next = head;
    10. ListNode cur = dummyHead;
    11. while (cur.next != null && cur.next.next != null){
    12. if(cur.next.val == cur.next.next.val){
    13. int x = cur.next.val;
    14. while (cur.next != null && cur.next.val == x){
    15. cur.next = cur.next.next;
    16. }
    17. }else {
    18. cur = cur.next;
    19. }
    20. }
    21. return dummyHead.next;
    22. }
    23. }