Simple solution by level order traversal


  • 0
    L
    public class Solution {
        public int findBottomLeftValue(TreeNode root) {
            Queue<TreeNode> queue = new LinkedList<>();
            queue.offer(root);
            TreeNode last = null;
            
            while(!queue.isEmpty()) {  //traver from right to left
                last = queue.poll();
                if(last.right != null) queue.offer(last.right);
                if(last.left != null) queue.offer(last.left);
            }
            
            return last.val;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.