前中后序遍历
https://leetcode.cn/leetbook/read/data-structure-binary-tree/xeywh5/
层序遍历
102. 二叉树的层序遍历
107. 二叉树的层序遍历 II
199. 二叉树的右视图
637. 二叉树的层平均值
429. N 叉树的层序遍历
515. 在每个树行中找最大值
// DFSclass Solution {List<Integer> ans = new ArrayList<Integer>();public List<Integer> largestValues(TreeNode root) {dfs(root,0);return ans;}void dfs(TreeNode root,int height) {if (root == null) return;if (ans.size() <= height) {ans.add(root.val);} else {ans.set(height,Math.max(ans.get(height),root.val));}if (root.left != null) {dfs(root.left,height + 1);}if (root.right != null) {dfs(root.right,height + 1);}}}
// BFS
class Solutin {
public List<Integer> largestValues(TreeNode root) {
}
}
