实际上也是广度优先搜索,不过有了一点改变,先右在左,等于镜像的广度优先遍历
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int findBottomLeftValue(TreeNode root) {
LinkedList<TreeNode> ll = new LinkedList<TreeNode>();
ll.offer(root);
while (!ll.isEmpty()) {
root = ll.poll();
if (root.right != null) ll.offer(root.right);//先右在左,相当与镜像的右边第一个
if (root.left != null) ll.offer(root.left);
}
return root.val;
}
}