My c++ solution


  • 1
    S
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> result;
        for (int i = 0; i < numRows; i++){
            vector<int> vec(i+1, 1);
            if (i != 0){
                for (int j = 1; j < i; j++)
                    vec[j] = (result.back())[j - 1] + (result.back())[j];
            }
            result.push_back(vec);
        }
        return result;
    }

Log in to reply
 

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