再删除时,处理下连续相同节点到情况 public ListNode deleteDuplicates (ListNode head) { // write code here if (head == null) { return head; } ListNode curNode = head; while (curNode != null && curNode.next != null) { if (curNode.val == curNode.next.val) { ListNode temp = curNode.next; // 当存在连续相同节点时,删除全部相同节点 while (temp != null && curNode.val == temp.val) { temp = temp.next; } curNode.next = temp; } curNode = curNode.next; } return head; }
点赞

相关推荐

08-05 18:14
门头沟学院 Java
小花的沉默:是学历厂没错啊,学历太高了不要
投递小鹏汽车等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务