We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c3636a commit d06ca13Copy full SHA for d06ca13
Surrounded Regions/Surrounded_Regions.cpp
@@ -1,4 +1,5 @@
1
// 解题思路依然使用并查集,特殊点在于使用了一个虚拟的父亲节点将所有边界上、以及边界上的邻居点都串起来了
2
+// 对于路径压缩,另外一种方法是https://leetcode.com/problems/surrounded-regions/discuss/41617/Solve-it-using-Union-Find,对路径长度减半
3
4
// Runtime: 24 ms, faster than 98.26% of C++ online submissions for Surrounded Regions.
5
// Memory Usage: 14.4 MB, less than 34.94% of C++ online submissions for Surrounded Regions.
@@ -42,7 +43,7 @@ class Solution
42
43
{
44
int index1 = i * cols + j;
45
- // 如果目标在边界上
46
+ // 如果目标在边界上,将其和一个dummy node连接在一起
47
if (i == 0 || i == rows - 1 || j == 0 || j == cols - 1)
48
49
int index2 = rows * cols;
@@ -142,4 +143,4 @@ class Solution
142
143
144
return index;
145
}
-};
146
+};
0 commit comments