You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,6 @@ You can skip the more difficult problems and do them later.
70
70
-[695. Max Area of Island](solutions/1-1000/695-max-area-of-island.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
71
71
-[827. Making A Large Island](solutions/1-1000/827-making-a-large-island.md) was solved in _Python_.
72
72
-[127. Word Ladder](solutions/1-1000/127-word-ladder.md) was solved in _Python_.
73
-
-[1971. Find if Path Exists in Graph](solutions/1001-2000/1971-find-if-path-exists-in-graph.md) was solved in _Python_.
73
+
-[1971. Find if Path Exists in Graph](solutions/1001-2000/1971-find-if-path-exists-in-graph.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and 2 solutions.
Copy file name to clipboardExpand all lines: solutions/1001-2000/1971-find-if-path-exists-in-graph-2.md
+222-9Lines changed: 222 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ And this graph may have multiple **connected components**. Initially, we start f
50
50
51
51
- We need to find if there is a path from `source` to `destination`. This question is equivalent to determine if `source` and `destination` vertices belong to the same `connected component`.
52
52
- A `tree` is a type of `graph`. If two nodes are in the same tree, then return `true`. So we need a method `in_same_tree(node1, node2)` to return a boolean value.
53
-
- We are `edges` data and need to divide them into multiple groups, each group can be abstracted into a **tree**.
53
+
- We are given `edges` data and need to divide them into multiple groups, each group can be abstracted into a **tree**.
54
54
-`UnionFind` algorithm is designed for grouping and searching data.
55
55
56
56
### 'UnionFind' algorithm
@@ -60,12 +60,12 @@ And this graph may have multiple **connected components**. Initially, we start f
60
60
- The `same_root(node1, node2)` method can be used to judge if two nodes are in the same tree.
61
61
62
62
## Approach (UnionFind algorithm)
63
-
1. Initially, every node is in the group of itself.
63
+
1. Initially, each node is in its own group.
64
64
1. Iterate `edges` data and `unite(node1, node2)`.
65
65
1. Return `same_root(source, destination)`.
66
66
67
67
## Complexity
68
-
* Time: `O(n)`.
68
+
* Time: `O(n)`.
69
69
* Space: `O(n)`.
70
70
71
71
## Python
@@ -144,32 +144,245 @@ class Solution:
144
144
145
145
## Java
146
146
```java
147
-
// Welcome to create a PR to complete the code of this language, thanks!
0 commit comments