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

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

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

/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param head ListNode类 
 * @return ListNode类
 */
#include <stdarg.h>
struct ListNode* deleteDuplicates(struct ListNode* head ) {
    // write code here
    struct ListNode* cur;
    struct ListNode* pre;
    if(head==NULL||head->next==NULL)
    return head;
    pre=head;
    cur=head->next;
    while(cur!=NULL)
    {
        if(pre->val!=pre->next->val)
        { 
            pre=pre->next;
            cur=pre->next;
        }
        else {
        pre->next=cur->next;
        cur=pre->next;
        }
    }
    return head;
}

全部评论

相关推荐

06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
zYvv:双一流加大加粗再标红,然后广投。主要是获奖荣誉不够,建议开始不用追求大厂,去别的厂子刷下实习。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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