0ms ans O(n) space ...Cpp solution..!!!


  • -1
    K
    class Solution {
    
    long long int ncr(int n,int r) { 
    
        if (r > n/2){
            r=n-r;
        }
        
        long long int ans=1;
        for (int i = 1; i <= r; i++){
            ans=ans*(n-r+i);
            ans=ans/i;
    	}
    	
        return(ans);
    }
        
        
    public:
        vector<int> getRow(int rowIndex) {
    
            vector<int> res(rowIndex+1);
            
            for(int i=0; i<=rowIndex; i++){
                long long int k= ncr(rowIndex,i);
                res[i]=(int)k;
            }
            
            return res;
        }
    };

Log in to reply
 

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