Skip to content

Commit d06ca13

Browse files
Update Surrounded_Regions.cpp
1 parent 5c3636a commit d06ca13

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Surrounded Regions/Surrounded_Regions.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// 解题思路依然使用并查集,特殊点在于使用了一个虚拟的父亲节点将所有边界上、以及边界上的邻居点都串起来了
2+
// 对于路径压缩,另外一种方法是https://leetcode.com/problems/surrounded-regions/discuss/41617/Solve-it-using-Union-Find,对路径长度减半
23

34
// Runtime: 24 ms, faster than 98.26% of C++ online submissions for Surrounded Regions.
45
// Memory Usage: 14.4 MB, less than 34.94% of C++ online submissions for Surrounded Regions.
@@ -42,7 +43,7 @@ class Solution
4243
{
4344
int index1 = i * cols + j;
4445

45-
// 如果目标在边界上
46+
// 如果目标在边界上,将其和一个dummy node连接在一起
4647
if (i == 0 || i == rows - 1 || j == 0 || j == cols - 1)
4748
{
4849
int index2 = rows * cols;
@@ -142,4 +143,4 @@ class Solution
142143

143144
return index;
144145
}
145-
};
146+
};

0 commit comments

Comments
 (0)