/** * @param {TreeNode} root * @return {number} */ var findBottomLeftValue = function (root) { // corner case if (root === null) { return -1; }
// normal case let res = null; let queue = [root]; while (queue.length > 0) { let cur = queue.shift(); res = cur.val; if (cur.right) { queue.push(cur.right); } if (cur.left) { queue.push(cur.left); } } return res; };
/** * Definition for a binary tree node. public class TreeNode { int val; TreeNode * left; TreeNode right; TreeNode(int x) { val = x; } } */ classSolution { intres=0; intheight=0;