O(1) space and O(n) easiest C++ solution


#1
#define ll unsigned long long 
int Solution::numTrees(int A) {

 
    ll up=1LL,n=A+A,d=1;
    for(ll i=A+2;i<=n;i++){
        up*=i;
        if(d<=A and up%d==0){
            up=up/d;
            d++;
        }
    }
    ll down=1;
    for(ll i=d;i<=A;i++)down*=i;
    ll ans=(up/down);
    return ans;
}