Since a tree is an undirected graph in which any two vertices are connected by exactly one path, the number of nodes should be 1 more than the number of edges. So the code should be very simple...

```
def validTree(self, n, edges):
return n == len(edges) + 1
```