mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-12-22 18:51:25 +01:00
4kyu(js): add „Sort binary tree by levels“
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
1811ab3c70
commit
4a94236571
2 changed files with 19 additions and 0 deletions
18
4kyu/sort_binary_tree_by_levels/solution.js
Normal file
18
4kyu/sort_binary_tree_by_levels/solution.js
Normal 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;
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue