分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

82. Remove Duplicates from Sorted List II(js)

发布时间:2023-09-06 02:35责任编辑:苏小强关键词:js

82. Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

Example 1:

Input: 1->2->3->3->4->4->5Output: 1->2->5

Example 2:

Input: 1->1->1->2->3Output: 2->3
题意:给定一个链表,删除所有有重复值的节点,返回这个链表
代码如下:
/** * Definition for singly-linked list. * function ListNode(val) { * ????this.val = val; * ????this.next = null; * } *//** * @param {ListNode} head * @return {ListNode} */var deleteDuplicates = function(head) { ???if(!head || !head.next) return head; ???let start=new ListNode(0); ???start.next=head; ???let pre=start; ???while(pre.next){ ???????let cur=pre.next; ???????while(cur.next && cur.next.val===cur.val) cur=cur.next; ???????if(cur!=pre.next) pre.next=cur.next; ???????else pre=pre.next; ???} ???return start.next;};

82. Remove Duplicates from Sorted List II(js)

原文地址:https://www.cnblogs.com/xingguozhiming/p/10582039.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved