import java.util.List;
import java.util.ArrayList;
import java.util.Stack;
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
         ArrayList<Integer> a = new ArrayList<Integer>();
        if(root == null)
            return a;
        Stack<TreeNode> stack = new Stack<TreeNode>();
        TreeNode current = root;
        while(!stack.isEmpty()|| current != null){
           if(current != null){
               //
                stack.push(current);
                current = current.left;
            }
            else{
                current = stack.pop();
                a.add(current.val);
                current = current.right;
            }
        }
        return a;
    }
}