一、normal fasion使用queue记录上次访问的是记录的孩子节点 1 public List> levelOrder(TreeNode root) { 2 List> res = new LinkedList>(); 3 Queue queue = new LinkedL
Given a binary tree, find the leftmost value in the last row of the tree. 就是拿到最后一层的第一个元素。 这个元素是最左下角的元素,不是最左侧的元素。 如果想实现 其实也很简单 就是维护更新每一层的第一个元素。 class Solution { public int findBottomLeftValue(TreeNode root) { if (root =...
分析:广搜,层序遍历,保存每层的第一个值,最后的即为所求值。 1/**2* Definition for a binary tree node.3* struct TreeNode {4* int val;5* TreeNode *left;6* TreeNode *right;7* TreeNode(int x) : val(x), left(NULL), right(NULL) {}8* };9*/10classSolution {11public:12intfindB...