My C++ code, 0ms, O(N^2)


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

Log in to reply
 

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