题解 | #删除有序链表中重复的元素-I#

删除有序链表中重复的元素-I

https://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79

/**
 * struct ListNode {
 *  int val;
 *  struct ListNode *next;
 * };
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 *
 * @param head ListNode类
 * @return ListNode类
 */
struct ListNode* deleteDuplicates(struct ListNode* head ) {
    // write code here
    struct ListNode* dest = head;

    while (dest) {
        if (!dest->next) {
            return head;
        }
        struct ListNode* cur = dest->next;
        while (cur) {
            if (cur->val == dest->val) {
                dest->next = cur->next;
            }
            cur = cur->next;
        }
        dest = dest->next;
    }
    return head;
}

全部评论

相关推荐

09-13 10:40
门头沟学院 Java
听别人介绍,刷了一堆力扣题,考场上写函数,一直无法通过。赛后才知道要自己写输入输出,力扣害人不浅
Silencer76:输入输出练习题单,请https://www.nowcoder.com/exam/oj?page=1&tab=%E7%AE%97%E6%B3%95%E7%AC%94%E9%9D%A2%E8%AF%95%E7%AF%87&topicId=372
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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