题解 | #从单向链表中删除指定值的节点#

从单向链表中删除指定值的节点

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

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, head, del; 
    vector<int> list;
    cin >> n >> head;
    list.push_back(head);
    while(n-- > 1){
        int front, behind;
        cin >> behind >> front;
        auto it = find(list.begin(), list.end(), front);
        list.insert(it+1, behind);
    }
    cin >> del;
    for(int it : list){
        if(it != del) cout << it << " ";
    }
    return 0;
}

全部评论

相关推荐

05-01 22:41
中南大学 Java
点赞 评论 收藏
分享
04-14 20:10
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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