mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 04:44:04 +00:00
[tree] getHeight returns faulty height bug fixed
This commit is contained in:
parent
dc2394ae4d
commit
07825744f4
|
@ -47,10 +47,8 @@ export class TreeNode<V = any> {
|
|||
}
|
||||
|
||||
getHeight() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const beginRoot = this;
|
||||
let maxDepth = 1;
|
||||
if (beginRoot) {
|
||||
let maxDepth = 0;
|
||||
if (this) {
|
||||
const bfs = (node: TreeNode<V>, level: number) => {
|
||||
if (level > maxDepth) {
|
||||
maxDepth = level;
|
||||
|
@ -62,7 +60,7 @@ export class TreeNode<V = any> {
|
|||
}
|
||||
}
|
||||
};
|
||||
bfs(beginRoot, 1);
|
||||
bfs(this, 0);
|
||||
}
|
||||
return maxDepth;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue