My C++ solution - 0 ms, O(k) space


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

Log in to reply
 

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