/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number[][]}
*/
var levelOrderBottom = function(root) {
var result = [];
if (root == null) {
return result;
}
var queue = [];
queue.push(root);
while (queue.length != 0) {
var size = queue.length;
var level = [];
for (var i = 0; i < size; i++) {
var node = queue.shift();
if (node.left != null) queue.push(node.left);
if (node.right != null) queue.push(node.right);
level.push(node.val);
}
result.push(level);
}
return result.reverse();
};
2016年8月23日星期二
[LeetCode]107. Binary Tree Level Order Traversal II
订阅:
博文评论 (Atom)
没有评论:
发表评论