> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/01-04-2022-94.md).

# 01/04/2022 94

```
class Solution { 
//recursive ways
public List inorderTraversal(TreeNode root) { 
  ArrayList result = new ArrayList<>(); traverse(root, result);
 return result;

}

public void traverse(TreeNode root, ArrayList<Integer> result){
    if (root == null){
        return;
    }
    traverse(root.left, result);
    result.add(root.val);
    traverse(root.right, result);
    
}
```

}

```
   class Solution { //iteration 
   public List inorderTraversal(TreeNode root) { 
      Stack<TreeNode> stack = new Stack<>(); 
      List<Integer> result = new ArrayList<>();
    
      while(!stack.isEmpty() || root != null){
        while(root != null){
            stack.push(root);
            root = root.left;
        }
    
        root = stack.pop();//Don't forget this one.
        result.add(root.val);
        root = root.right;
    }
    
    return result;
   
    
    
}
```

}
