1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-21 16:13:47 +01:00

4kyu(js): add „Sort binary tree by levels“

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-08-20 19:34:23 +02:00
parent 1811ab3c70
commit 4a94236571
Signed by: mfocko
GPG key ID: 7C47D46246790496
2 changed files with 19 additions and 0 deletions

View file

@ -0,0 +1,18 @@
function treeByLevels (rootNode) {
let queue = [rootNode];
let values = [];
while (queue.length > 0) {
let node = queue.shift();
if (node === null) {
continue;
}
values.push(node.value);
queue.push(node.left);
queue.push(node.right);
}
return values;
}

View file

@ -49,6 +49,7 @@
- [Priori Incantatem](https://www.codewars.com/kata/574d0b01b4b769b207000ca3) - [solution](4kyu/priori_incantatem)
- [ES5 Generators(i)](https://www.codewars.com/kata/53c29a6abb5187180d000b65) - [solution](4kyu/es5_generators_i)
- [Remove Zeros](https://www.codewars.com/kata/52aae14aa7fd03d57400058f) - [solution](4kyu/remove_zeros)
- [Sort binary tree by levels](https://www.codewars.com/kata/52bef5e3588c56132c0003bc) - [solution](4kyu/sort_binary_tree_by_levels)
### TS