---
# System prepended metadata

title: 0513. Find Bottom Left Tree Value
tags: [Leetcode, Level Order Traversal, Tree, Medium]

---

# 0513. Find Bottom Left Tree Value
###### tags: `Leetcode` `Medium` `Tree` `Level Order Traversal`
Link: https://leetcode.com/problems/find-bottom-left-tree-value/description/
## 思路
### Iterate from Right to Left
思路[参考](https://leetcode.com/problems/find-bottom-left-tree-value/solutions/98779/right-to-left-bfs-python-java/)
### Level Order Traversal
## Code
Iterate from Right to Left
```java=
class Solution {
    public int findBottomLeftValue(TreeNode root) {
        Queue<TreeNode> q = new LinkedList<>();
        q.add(root);
        TreeNode cur = root;
        while(!q.isEmpty()){
            cur = q.poll();
            if(cur.right!=null) q.add(cur.right);
            if(cur.left!=null) q.add(cur.left);
        }
        return cur.val;
    }
}
```
Level Order Traversal
```java=
class Solution {
    public int findBottomLeftValue(TreeNode root) {
        Queue<TreeNode> q = new LinkedList<>();
        q.add(root);
        TreeNode ans = root;
        while(!q.isEmpty()){
            int size = q.size();
            for(int i=0; i<size; i++){
                TreeNode cur = q.poll();
                if(i==0) ans = cur;
                if(cur.left!=null) q.add(cur.left);
                if(cur.right!=null) q.add(cur.right);
            }
        }
        return ans.val;
    }
}
```