File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 409
409
507|[ Perfect Number] ( ./0507-perfect-number.js ) |Easy|
410
410
508|[ Most Frequent Subtree Sum] ( ./0508-most-frequent-subtree-sum.js ) |Medium|
411
411
509|[ Fibonacci Number] ( ./0509-fibonacci-number.js ) |Easy|
412
+ 513|[ Find Bottom Left Tree Value] ( ./0513-find-bottom-left-tree-value.js ) |Medium|
412
413
520|[ Detect Capital] ( ./0520-detect-capital.js ) |Easy|
413
414
521|[ Longest Uncommon Subsequence I] ( ./0521-longest-uncommon-subsequence-i.js ) |Easy|
414
415
530|[ Minimum Absolute Difference in BST] ( ./0530-minimum-absolute-difference-in-bst.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 513. Find Bottom Left Tree Value
3
+ * https://leetcode.com/problems/find-bottom-left-tree-value/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given the root of a binary tree, return the leftmost value in the last row of the tree.
7
+ */
8
+
9
+ /**
10
+ * Definition for a binary tree node.
11
+ * function TreeNode(val, left, right) {
12
+ * this.val = (val===undefined ? 0 : val)
13
+ * this.left = (left===undefined ? null : left)
14
+ * this.right = (right===undefined ? null : right)
15
+ * }
16
+ */
17
+ /**
18
+ * @param {TreeNode } root
19
+ * @return {number }
20
+ */
21
+ var findBottomLeftValue = function ( root ) {
22
+ const queue = [ root ] ;
23
+ let result = root . val ;
24
+
25
+ while ( queue . length ) {
26
+ const size = queue . length ;
27
+ result = queue [ 0 ] . val ;
28
+ for ( let i = 0 ; i < size ; i ++ ) {
29
+ const node = queue . shift ( ) ;
30
+ if ( node . left ) queue . push ( node . left ) ;
31
+ if ( node . right ) queue . push ( node . right ) ;
32
+ }
33
+ }
34
+
35
+ return result ;
36
+ } ;
You can’t perform that action at this time.
0 commit comments