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

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

https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f?tpId=37&tqId=21271&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=

#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int e[1010];
int ne[1010];
int cnt = 0;

int main() {
    int n=0;
    int m;
    scanf("%d %d",&n,&m);
    memset(ne,-1,sizeof ne);
    e[cnt++] = m;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        for(int j=0;j<cnt;j++)
        {
            if(e[j]==b)
            {
                ne[cnt] = ne[j];
                ne[j] = cnt;
                e[cnt++] = a;
            }
        }
    }
    int x;
    scanf("%d",&x);
    for(int i=0;i!=-1;i=ne[i])
    {
        if(e[i]!=x)
        {
            printf("%d ",e[i]);
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

02-25 11:29
产品经理
牛客444597598号:兄弟 我只能说如果想找产品经理这种简历 基本就是毕业失业了 你这连实习都找不到的 简历跟产品经理一点都没有关系,你可以去搜搜产品的模版吧
点赞 评论 收藏
分享
暮雨轻歌:看起来hr不能接受我菜查看图片
点赞 评论 收藏
分享
03-13 12:48
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务