思路
先推右边再推左边,左边就是队列里的最后一个了
复制代码
源码
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var findBottomLeftValue = function(root) {
let q = [];
let res;
q.push(root);
while(q.length){
let node = q.shift();
res = node.val;
if(node.right){
q.push(node.right);
}
if(node.left){
q.push(node.left);
}
}
return res;
};
复制代码