Code with only O(K) space compexity.


  • 0
    C
        class Solution {
         public:
        vector<int> getRow(int rowIndex) {    
        vector<int> v(rowIndex+1);
        int i,j,k;
        
        if(rowIndex == 0)
            return {1};
        
        v[0] = 1;
        
        for(i=1;i<=rowIndex;i++){
            
            k = 1;
            
            for(j=1;j<i;j++){
                
                int temp = v[j];
                
                v[j] = v[j] + k;
                
                k = temp;
                
            }
            
            v[j] = 1;
        }
        
        return v;
        
    }
    

    };


Log in to reply
 

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