LeetCode-513. Find Bottom Left Tree Value

Given a binary tree, find the leftmost value in the last row of the tree.

Example 1:

Input:
    2
   / \
  1   3
Output:
1

Example 2: 

Input:
        1
       / \
      2   3
     /   / \
    4   5   6
       /
      7
Output:
7
    public int findBottomLeftValue(TreeNode root) {
        LinkedList<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        TreeNode cur = root;
        while(!queue.isEmpty()){
            cur = queue.poll();
            if(cur.right!=null){
                queue.offer(cur.right);
            }
            if(cur.left!=null){
                queue.offer(cur.left);
            }
        }
        return cur.val;
    }

 

posted @ 2019-07-17 18:33  月半榨菜  阅读(71)  评论(0编辑  收藏  举报