前中后序遍历

https://leetcode.cn/leetbook/read/data-structure-binary-tree/xeywh5/

层序遍历

102. 二叉树的层序遍历
107. 二叉树的层序遍历 II
199. 二叉树的右视图
637. 二叉树的层平均值
429. N 叉树的层序遍历

515. 在每个树行中找最大值

  1. // DFS
  2. class Solution {
  3. List<Integer> ans = new ArrayList<Integer>();
  4. public List<Integer> largestValues(TreeNode root) {
  5. dfs(root,0);
  6. return ans;
  7. }
  8. void dfs(TreeNode root,int height) {
  9. if (root == null) return;
  10. if (ans.size() <= height) {
  11. ans.add(root.val);
  12. } else {
  13. ans.set(height,Math.max(ans.get(height),root.val));
  14. }
  15. if (root.left != null) {
  16. dfs(root.left,height + 1);
  17. }
  18. if (root.right != null) {
  19. dfs(root.right,height + 1);
  20. }
  21. }
  22. }
// BFS
class Solutin {
    public List<Integer> largestValues(TreeNode root) {

    }
}

116. 填充每个节点的下一个右侧节点指针
117. 填充每个节点的下一个右侧节点指针 II