clueless coding // TODO: be smarter

LeetCode Pascal's Triangle: CPP Solution



TL;DR Code Solution


vector<vector<int>> generate(int numRows) {

    vector<vector<int>> result;
    if (numRows == 0) {
        return result;
    }

    vector<int> current = { 1 };
    result.push_back(current);

    for (int i = 2; i <= numRows; i++) {
        current.push_back(0);
        int n = current.size();
        for (int j = n - 1; j >= 1; j--) {
            current[j] += current[j - 1];
        }
        result.push_back(current);
    }

    return result;



}