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

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

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

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
// struct Node{
//     int val;
//     Node* next;
// };

int main() {
    int num,head;
    cin>>num>>head;
    int val,wz;
    vector<int> lt;
    lt.push_back(head);
    vector<int>::iterator it;
    for(int i = 0;i<num-1;i++){
        cin>>val;
        cin>>wz;
        it = find(lt.begin(),lt.end(),wz);
        lt.insert(it+1, val);
    }
    int er;
    cin>>er;
    it = find(lt.begin(),lt.end(),er);
    lt.erase(it);
    for(int i= 0;i<lt.size();i++){
        cout<<lt[i]<<' ';
    }
    
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

牛客773130651号:巨佬,简历模板换成上下的,左右的很烦,hr看着不爽。。。科大随便乱杀,建议能保研就保研,不行也得考一下 ,985硕去干算法,比开发强多了。开发许多双非都能搞,学历优势用不上,算法有门槛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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