94. 二叉树的中序遍历 - 力扣(LeetCode)
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> list = new ArrayList<>();
in(root,list);
return list;
}
public void in(TreeNode root , List<Integer> list){
if(root != null){
in(root.left, list);
list.add(root.val);
in(root.right,list);
}
}
}