解法一
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
List<Integer> ans;
public List<Integer> inorderTraversal(TreeNode root) {
ans = new LinkedList<>();
inOrder(root);
return ans;
}
private void inOrder(TreeNode root) {
if (root == null) {
return;
}
inOrder(root.left);
ans.add(root.val);
inOrder(root.right);
}
}