今天看到一片好贴讲王石为何众叛亲离# Joke - 肚皮舞运动
a*r
1 楼
// Write a function that takes this data as input and returns two
collections: one containing all individuals with zero known parents, and one
containing all individuals with exactly one known parent.
// Parents are above children:
// 1 2 4
// / /
// 3 5 8
// /
// 6 7 10
// findNodesWithZeroAndOneParents(parentChildPairs) => [
// [1, 2, 4], // Individuals with zero parents
// [5, 7, 8, 10] // Individuals with exactly one parent
// ]
The input is
// (parent, child)
vector> parentChildPairs = {
std::make_pair(1, 3),
std::make_pair(2, 3),
std::make_pair(3, 6),
std::make_pair(5, 6),
std::make_pair(5, 7),
std::make_pair(4, 5),
std::make_pair(4, 8),
std::make_pair(8, 10)
};
用unordered_map了,但Individuals with zero parents没弄对,大牛能不能贡献一下
C++ code
collections: one containing all individuals with zero known parents, and one
containing all individuals with exactly one known parent.
// Parents are above children:
// 1 2 4
// / /
// 3 5 8
// /
// 6 7 10
// findNodesWithZeroAndOneParents(parentChildPairs) => [
// [1, 2, 4], // Individuals with zero parents
// [5, 7, 8, 10] // Individuals with exactly one parent
// ]
The input is
// (parent, child)
vector
std::make_pair(1, 3),
std::make_pair(2, 3),
std::make_pair(3, 6),
std::make_pair(5, 6),
std::make_pair(5, 7),
std::make_pair(4, 5),
std::make_pair(4, 8),
std::make_pair(8, 10)
};
用unordered_map了,但Individuals with zero parents没弄对,大牛能不能贡献一下
C++ code