10 lines 0ms C++ solution


  • 4
    N
    vector<int> getRow(int rowIndex) {
        vector<int> pascal(rowIndex+1, 0);
        pascal[0]=1;
        for(int i=1; i<rowIndex+1; ++i){
            for(int j=i; j>0; j--){
                pascal[j] += pascal[j-1];
            }
        }
        return pascal;
    }

  • 0
    S

    one similar solution:

    vector<int> getRow(int rowIndex) {
        vector<int> result(rowIndex + 1, 1);
        for (int i = 1; i <= rowIndex; i++){
            for (int j = i - 1; j > 0; j--)
                result[j] += result[j - 1];
        }
        return result;
    }

Log in to reply
 

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