public int numTrees(int n) {
        if (n < result.size())
            return result.get(n);

        int temp = 0;
        for (int i = 0; i < n; i++) {
            temp += numTrees(i) * numTrees(n - 1 - i);
        }
        result.add(temp);
        return temp;
    }