[LeetCode] Pascal's Triangle II

class Solution {
public:
    vector<int> getRow(int rowIndex) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        vector<int> ret(rowIndex + 1, 1);
        
        for (int i = 1; i < rowIndex; i++)
        for (int j = i; j >= 1; j--)
            ret[j] += ret[j - 1];
        
        return ret;
    }
};

Small Case: 4ms

Large Case: 12ms

Time: O(n^2)

Space: O(n)

点赞