Skip to content

Commit 2341db9

Browse files
committed
1118
1 parent 681542d commit 2341db9

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Feel free to submit pull requests, add issues and be a contributer.
142142
| Leetcode | [298. Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/description/) | [Java](./java/longestConsecutive.java) | O(n) | O(n) | Medium | |
143143
| Leetcode | [314. Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal/description/) | [Java](./java/verticalOrder.java) | O(n) | O(n) | Medium | |
144144
| Leetcode | [437. Path Sum III](https://leetcode.com/problems/path-sum-iii/description/) | [Java](./java/pathSumiii.java) | O(n) | O(1) | Easy | |
145+
| Leetcode | [513. Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value/description/) | [Java](./java/findBottomLeftValue.java) | O(n^2) | O(1) | Medium | |
145146
| Leetcode | [530. Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst/description/) | [Java](./java/getMinimumDifference.java) | O(v + e) | O(1) | Easy | |
146147
| Leetcode | [543. Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/description/) | [Java](./java/diameterOfBinaryTree.java) | O(v + e) | O(1) | Easy | |
147148
| Leetcode | [572. Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/description/) | [Java](./java/isSubtree.java) | O(m2+n2+mn) | O(max(m,n) | Easy | |

java/findBottomLeftValue.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode(int x) { val = x; }
8+
* }
9+
*/
10+
class Solution {
11+
public int findBottomLeftValue(TreeNode root) {
12+
if(root == null) return 0;
13+
14+
int result = 0;
15+
Queue<TreeNode> queue = new LinkedList<>();
16+
queue.add(root);
17+
18+
while(!queue.isEmpty())
19+
{
20+
int size = queue.size();
21+
for(int i=0; i<size; i++)
22+
{
23+
TreeNode node = queue.poll();
24+
if(i==0) result = node.val;
25+
if(node.left != null) queue.add(node.left);
26+
if(node.right != null) queue.add(node.right);
27+
}
28+
}
29+
return result;
30+
}
31+
}

0 commit comments

Comments
 (0)