给出二叉树,求出其中序遍历
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
static ArrayList<Integer> ans ;
public ArrayList<Integer> inorderTraversal(TreeNode root) {
ans = new ArrayList<>();
travel(root);
return ans;
}
void travel(TreeNode node){
if(node != null ){
travel(node.left);
ans.add(node.val);
travel(node.right);
}
}
}