Skip to content

Commit

Permalink
Time: 70 ms (28.65%) | Memory: 53 MB (58.48%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Feb 28, 2024
1 parent 7d0f5fb commit ba81d55
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 513-find-bottom-left-tree-value/find-bottom-left-tree-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var findBottomLeftValue = function(root) {

const queue = [root];
let leftmostValue;

while (queue.length > 0) {
const node = queue.shift();

leftmostValue = node.val;

if (node.right) {
queue.push(node.right);
}
if (node.left) {
queue.push(node.left);
}
}

return leftmostValue;
};

0 comments on commit ba81d55

Please sign in to comment.