思路
先推右邊再推左邊,左邊就是佇列裡的最後一個了
複製程式碼
原始碼
/**
* 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;
};
複製程式碼