We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e144953 commit dd5f7e7Copy full SHA for dd5f7e7
107-binary-tree-level-order-traversal-ii.js
@@ -23,3 +23,23 @@ const levelOrderBottom = function(root) {
23
}
24
25
26
+
27
+// another
28
29
+const levelOrderBottom = function(root) {
30
+ if (!root) return []
31
+ const currentLevelNodes = [root]
32
+ const result = []
33
+ while (currentLevelNodes.length > 0) {
34
+ const count = currentLevelNodes.length
35
+ const currentLevelValues = []
36
+ for (let i = 0; i < count; i++) {
37
+ const node = currentLevelNodes.shift()
38
+ currentLevelValues.push(node.val)
39
+ if (node.left) currentLevelNodes.push(node.left)
40
+ if (node.right) currentLevelNodes.push(node.right)
41
+ }
42
+ result.unshift(currentLevelValues)
43
44
+ return result
45
+}
0 commit comments