题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
#include <cstring> #include <iostream> using namespace std; int ne[10010]; int main() { int n ; int hn; cin >> n >> hn; int nc = n; memset(ne, -1, sizeof(ne)); n--; while (n) { int a, b; cin >> a >> b; if (ne[b] != -1) { int sw = ne[b]; ne[b] = a; ne[a] = sw; } else { ne[b] = a; } n--; } int de; cin >> de; while (hn!=-1) { if (hn == de) { hn = ne[hn]; continue; }; cout << hn << ' '; hn = ne[hn]; } } // 64 位输出请用 printf("%lld")