题解 | #删除有序链表中重复的元素-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
};
全部评论

相关推荐

07-01 19:00
门头沟学院 Java
点赞 评论 收藏
分享
_mos_:我以为手抄报简历就已经很顶了,没想到还有表格简历
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务