只用看它们的next指针是否有重合即可
Sharing
https://www.nowcoder.com/practice/2577bea713cf4eed874afccff1928113
#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
int start1, start2, n;
while (cin >> start1 >> start2 >> n) {
unordered_set<int> set;
while (n--) {
int cur, next;
char c;
cin >> cur >> c >> next;
if (set.count(next) == 0) set.insert(next);
else {
cout << next << endl;
}
}
}
return 0;
}
查看30道真题和解析