My Simple 2ms DP solution


  • 1
    N
    class Solution {
    public:
        int numTrees(int n) {
            map<int, int> Mymap;
    		Mymap[0] = 1;
    		for (int i = 1; i <= n; i++){
    		    int cont = 0;
    			for (int k = 0; k < i; k++)
    			cont+= Mymap[k] * Mymap[i - 1 - k];
    			Mymap[i] = cont;
    		}
    		return Mymap[n];
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.