题解 | #删除有序链表中重复的元素-I#
删除有序链表中重复的元素-I
https://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79
/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* @param head ListNode类
* @return ListNode类
*/
function deleteDuplicates( head ) {
// write code here
if(!head)return null;
let p=head,q;
while(p!=null&&p.next){
if(p&&!p.next)return p;
q=p.next;
if(p.val==q.val){
p.next=q.next;
q=null;
}else{
p=p.next;
}
}
return head;
}
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)return null;
let p=head,q;
while(p!=null&&p.next){
if(p&&!p.next)return p;
q=p.next;
if(p.val==q.val){
p.next=q.next;
q=null;
}else{
p=p.next;
}
}
return head;
}
module.exports = {
deleteDuplicates : deleteDuplicates
};