首页 > 其他 > 详细

剑指OFFER----面试题18. 删除链表的节点

时间:2020-02-21 12:29:19      阅读:51      评论:0      收藏:0      [点我收藏+]

链接:https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/submissions/

 

代码:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */

 class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        if (head->val == val) return head->next;
        ListNode* ret = head;
        while (ret->next->val != val) ret = ret->next;
        ret->next = ret->next->next;
        return head;
    }
};

 

剑指OFFER----面试题18. 删除链表的节点

原文:https://www.cnblogs.com/clown9804/p/12340429.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!