Skip to content

Commit 5f741b8

Browse files
committed
Update number-of-connected-components-in-an-undirected-graph.cpp
1 parent f3ec9f2 commit 5f741b8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

C++/number-of-connected-components-in-an-undirected-graph.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,21 @@ class Solution {
1414
private:
1515
class UnionFind {
1616
public:
17-
UnionFind(const int n) : set(n) {
18-
iota(set.begin(), set.end(), 0);
19-
count_ = n;
17+
UnionFind(const int n) : set_(n), count_(n) {
18+
iota(set_.begin(), set_.end(), 0);
2019
}
2120

2221
int find_set(int x) {
23-
if (set[x] != x) {
24-
set[x] = find_set(set[x]); // Path compression.
22+
if (set_[x] != x) {
23+
set_[x] = find_set(set_[x]); // Path compression.
2524
}
26-
return set[x];
25+
return set_[x];
2726
}
2827

2928
void union_set(const int x, const int y) {
3029
int x_root = find_set(x), y_root = find_set(y);
3130
if (x_root != y_root) {
32-
set[min(x_root, y_root)] = max(x_root, y_root);
31+
set_[min(x_root, y_root)] = max(x_root, y_root);
3332
--count_;
3433
}
3534
}
@@ -39,7 +38,7 @@ class Solution {
3938
}
4039

4140
private:
42-
vector<int> set;
41+
vector<int> set_;
4342
int count_;
4443
};
4544
};

0 commit comments

Comments
 (0)