再删除时,处理下连续相同节点到情况 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; }
点赞

相关推荐

不愿透露姓名的神秘牛友
07-11 15:37
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
Steven267:这不喷回去?花钱是大爷,记住这个道理
点赞 评论 收藏
分享
Lorn的意义:你这种岗位在中国现在要么牛马天天加班,要么关系户进去好吃好喝,8年时间,真的天翻地覆了,对于资本来说你就说一头体力更好的牛马,哎,退伍没有包分配你真的亏了。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务