Joey LIU | NANTSOU


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
/**
 * Key point is that inorder traversal is left -> root -> right.
 */
class Solution {
    List<Integer> res = new ArrayList<>();
    
    public List<Integer> inorderTraversal(TreeNode root) {
        travel(root);
        return res;
    }
    
    private void travel(TreeNode node) {
        if (node == null) return;
        travel(node.left);
        res.add(node.val);
        travel(node.right);
    }
}