leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit55f537f6393e910be3212e4812560fcd072cd6f3
parent55ae892793093808585469747344fb139da57a15
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSun, 25 Feb 2024 14:47:53 +0000

Improve UnionFind template Add reset() to return to starting state

Diffstat:
MTemplates/Union_Find.cpp|+++++

1 files changed, 5 insertions(+), 0 deletions(-)


diff --git a/Templates/Union_Find.cpp b/Templates/Union_Find.cpp

@@ -29,6 +29,11 @@ class UnionFind {

size[x] = 0;
}
void reset() {
memset(size.data(), 0x00, size.size() * sizeof(int));
iota(begin(root), end(root), 0);
}
int count() const { return cnt; }
bool connected(int x, int y) const { return find(x) == find(y); }
};