/* function TreeNode(x) {
this.val = x;
this.left = null;
this.right = null;
} */
function PrintFromTopToBottom(root)
{
// write code here
//使用bsf的思路即可
let arr = [];
let ret = [];
if(!root) return [];
arr = [root];
while(arr.length){
let head = arr.shift();
ret.push(head.val)
if(head.left) arr.push(head.left)
if(head.right) arr.push(head.right)
}
return ret
}
module.exports = {
PrintFromTopToBottom : PrintFromTopToBottom
}; 


京公网安备 11010502036488号