中序遍历
public static void inorder(TreeNode node,List<Integer> list){if (node==null){return;}inorder(node.left,list);list.add(node.val);inorder(node.right,list);}
深度优先
/**
* DFS
* @param root
* @return
*/
public int maxDepth(TreeNode root) {
if (root==null){
return 0;
}else {
int left=maxDepth(root.left);
int right=maxDepth(root.right);
return Math.max(left,right)+1;
}
}
