C++ 6 lines without extra memory usage


  • 4
    L
    class Solution {
    public:
        vector<int> getRow(int rowIndex) {
            
            vector<int> row(rowIndex+1,0);
            row[0]=1;
            for(int i=1;i<=rowIndex;i++)
                for(int j=i;j>=1;j--)
                    row[j]=row[j-1]+row[j];
    
            return(row);
        }
    };

Log in to reply
 

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