261. Graph Valid Tree

Practice Graph Valid Tree for free on NudgeCode: Medium, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

You have n nodes labeled 0 to n - 1 and a list of undirected edges. Return true if these edges form a valid tree: every node is connected and there are no cycles.

Example

n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]  ->  true

Constraints