public List<Integer> inorderTraversal_v2(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        if (root == null)
            return ans;
        Stack<TreeNode> stack = new Stack<>();
        while (root != null) {
            stack.push(root);
            root = root.left;
        }
        while (!stack.isEmpty()) {
            TreeNode node = stack.pop();
            ans.add(node.val);
            TreeNode right = node.right;
            while (right != null) {
                stack.push(right);
                right = right.left; // get left of the right node
            }
        }
        return ans;
    }