Skip to content

Commit 55482be

Browse files
committed
feat: add solutions to lc problem: No. 3378
1 parent c039cc7 commit 55482be

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

solution/3300-3399/3378.Count Connected Components in LCM Graph/Solution1.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ typedef struct DSU {
3232

3333
class Solution {
3434
public:
35-
int countComponents(vector<int> &nums, int threshold) {
35+
int countComponents(vector<int>& nums, int threshold) {
3636
DSU dsu(threshold);
37-
for (auto &num : nums) {
37+
for (auto& num : nums) {
3838
for (int j = num; j <= threshold; j += num) {
3939
dsu.unionSet(num, j);
4040
}
4141
}
4242
unordered_set<int> par;
43-
for (auto &num : nums) {
43+
for (auto& num : nums) {
4444
if (num > threshold) {
4545
par.insert(num);
4646
} else {

solution/3300-3399/3378.Count Connected Components in LCM Graph/Solution2.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
class Solution {
22
private:
3-
void dfs(int node, vector<vector<int>> &adj, vector<bool> &vis) {
3+
void dfs(int node, vector<vector<int>>& adj, vector<bool>& vis) {
44
if (vis[node]) return;
55
vis[node] = true;
6-
for (auto &u : adj[node]) {
6+
for (auto& u : adj[node]) {
77
dfs(u, adj, vis);
88
}
99
}
1010

1111
public:
12-
int countComponents(vector<int> &nums, int threshold) {
12+
int countComponents(vector<int>& nums, int threshold) {
1313
vector<vector<int>> adj(threshold + 1);
1414
vector<bool> vis(threshold + 1, false);
1515
int ans = 0;
16-
for (auto &num : nums) {
16+
for (auto& num : nums) {
1717
if (num > threshold) {
1818
++ans;
1919
continue;
@@ -23,7 +23,7 @@ class Solution {
2323
adj[j].push_back(num);
2424
}
2525
}
26-
for (auto &num : nums) {
26+
for (auto& num : nums) {
2727
if (num <= threshold && !vis[num]) {
2828
dfs(num, adj, vis);
2929
++ans;

0 commit comments

Comments
 (0)