Simple C++ Two Loops Solution


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

Log in to reply
 

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