题解 | #删除有序链表中重复的元素-II#
删除有序链表中重复的元素-II
https://www.nowcoder.com/practice/71cef9f8b5564579bf7ed93fbe0b2024
/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* @param head ListNode类
* @return ListNode类
*/
function deleteDuplicates( head ) {
// write code here
if(head == null || head.next == null){ return head}
const top = {}
top.next = head
var current = top
while(current.next && current.next.next){
if(current.next.val == current.next.next.val){
var val = current.next.val
while(current.next && current.next.val == val){
current.next = current.next.next
}
}else{
current = current.next
}
}
return top.next
}
module.exports = {
deleteDuplicates : deleteDuplicates
};
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* @param head ListNode类
* @return ListNode类
*/
function deleteDuplicates( head ) {
// write code here
if(head == null || head.next == null){ return head}
const top = {}
top.next = head
var current = top
while(current.next && current.next.next){
if(current.next.val == current.next.next.val){
var val = current.next.val
while(current.next && current.next.val == val){
current.next = current.next.next
}
}else{
current = current.next
}
}
return top.next
}
module.exports = {
deleteDuplicates : deleteDuplicates
};