LeetCode 684. Redundant Connection
We are given a “tree” in the form of a 2Darray, with distinct
values for each node.
In the given 2Darray, each element pair [u, v]
represents that v
is a child of u
in the tree.
We can remove exactly
one redundant pair in this “tree” to make the result a tree.
You need to find and output such a pair. If there are multiple answers for this question, output the one appearing last in the 2Darray. There is always at least one answer.
Example 1:


Example 2:


Note:
The size of the input 2Darray will be between 1 and 1000.
Every integer represented in the 2Darray will be between 1 and 2000.