1197 · 寻找树中最左下结点的值
方法1:BFS
public int findBottomLeftValue(TreeNode root) {
Queue<TreeNode> q = new LinkedList<>();
int res = 0;
q.offer(root);
while (!q.isEmpty()) {
int size = q.size();
for (int i = 0; i < size; i++) {
TreeNode cur = q.poll();
res = cur.val;
if (cur.right != null) q.offer(cur.right);
if (cur.left != null) q.offer(cur.left);
}
}
return res;
}