Skip to content

Commit 07058a2

Browse files
edit 261
1 parent 8daf5df commit 07058a2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ Your ideas/fixes/algorithms are more than welcome!
319319
|265|[Paint House II](https://leetcode.com/problems/paint-house-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/PaintHouseII.java)| ?|? | Hard|
320320
|264|[Ugly Number II](https://leetcode.com/problems/ugly-number-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_264.java)| O(n)|O(n) | Medium| DP
321321
|263|[Ugly Number](https://leetcode.com/problems/ugly-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_263.java)| O(n)|O(1) | Easy|
322-
|261|[Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/GraphValidTree.java)| O(V+E)|O(V+E) | Medium|
322+
|261|[Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_261.java)| O(V+E)|O(V+E) | Medium|
323323
|260|[Single Number III](https://leetcode.com/problems/single-number-iii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_260.java)| O(n)|O(n) | Medium|
324324
|259|[3Sum Smaller](https://leetcode.com/problems/3sum-smaller/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_259.java)| O(n^2)|O(1) | Medium|
325325
|258|[Add Digits](https://leetcode.com/problems/add-digits/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_258.java)| O(1)|O(1) | Easy|

src/main/java/com/fishercoder/solutions/GraphValidTree.java renamed to src/main/java/com/fishercoder/solutions/_261.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.fishercoder.solutions;
22

33
/**
4-
* Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.
4+
*261. Graph Valid Tree
5+
*Given n nodes labeled from 0 to n - 1 and a list of undirected edges
6+
* (each edge is a pair of nodes),
7+
* write a function to check whether these edges make up a valid tree.
58
69
For example:
710
@@ -12,10 +15,14 @@
1215
Hint:
1316
1417
Given n = 5 and edges = [[0, 1], [1, 2], [3, 4]], what should your return? Is this case a valid tree?
15-
According to the definition of tree on Wikipedia: “a tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.”
16-
Note: you can assume that no duplicate edges will appear in edges. Since all edges are undirected, [0, 1] is the same as [1, 0] and thus will not appear together in edges.
18+
According to the definition of tree on Wikipedia:
19+
“a tree is an undirected graph in which any two vertices are connected by exactly one path.
20+
In other words, any connected graph without simple cycles is a tree.”
21+
22+
Note: you can assume that no duplicate edges will appear in edges.
23+
Since all edges are undirected, [0, 1] is the same as [1, 0] and thus will not appear together in edges.
1724
*/
18-
public class GraphValidTree {
25+
public class _261 {
1926

2027
public boolean validTree(int n, int[][] edges){
2128
int[] nums = new int[n];

0 commit comments

Comments
 (0)