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

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

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

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int num;
    cin>>num;
    int first;
    cin>>first;
    vector<int> temp;
    vector<int>::iterator it;
    temp.push_back(first);
    for(int i=0;i<num-1;i++){
        int val;
        int node;
        cin>>val;
        cin>>node;
        for(int j=0;j<temp.size();j++){
            if(temp[j] == node){
                if(j==temp.size()-1){
                    temp.push_back(val);
                }else{
                    it=temp.begin();
                    temp.insert(it+j+1,val);
                }
                break;
            }
        }

    }

    int end;
    cin>>end;
    for(auto a:temp){
        if(a==end)
            continue;
        cout<<a<<" ";
    }
    cout<<endl;
    return 0;

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
已注销:同学,瞅瞅我司,金山办公WPS,校招刚开,点击就送,我的主页最新动态,绿灯直达~
秋招的第一个offer,...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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