The number of nodes in the tree is in the range [1, 104].
-231 <= Node.val <= 231 - 1
ac
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */classSolution {publicintfindBottomLeftValue(TreeNode root) {Queue<TreeNode> q =newLinkedList<>();q.offer(root);int res =0;while (!q.isEmpty()) {int len =q.size();for (int i =0; i < len; i++) {TreeNode curr =q.poll();if (i ==0) res =curr.val;if (curr.left!=null) q.offer(curr.left);if (curr.right!=null) q.offer(curr.right); } }return res; }}/*just BFS, pick the first node of each level*/