Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

For O(n^2): Go from end to start, check if the rest can form a tree, this one will get AC surprisingly.

For O(n): If we have a node with two parent, the answer must be the one of them. Else, the answer is the first one that form a loop.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.