Sharing my C++ solution


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

Log in to reply
 

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