Skip to content

Commit af916e2

Browse files
committed
Update graph-valid-tree.cpp
1 parent 2eb1d70 commit af916e2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

C++/graph-valid-tree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// Time: O(|V| + |E|)
32
// Space: O(|V| + |E|)
43

@@ -33,6 +32,7 @@ class Solution {
3332
const int i = q.front();
3433
q.pop();
3534
visited.emplace(i);
35+
--n;
3636
for (const auto& n : nodes[i].neighbors) {
3737
if (n != nodes[i].parent) {
3838
if (visited.find(n) != visited.end()) {
@@ -45,6 +45,6 @@ class Solution {
4545
}
4646
}
4747
}
48-
return true;
48+
return n == 0;
4949
}
5050
};

0 commit comments

Comments
 (0)