A math solution with O(K) time complexity and O(1) Space


  • 0
    5
    vector<int> getRow(int rowIndex) {
            vector<int> res;
            if(rowIndex < 0)return res;
            long long elmt = 1;
            res.push_back(elmt);
            for(long long i = 1;i <= rowIndex;i++)
            {
                elmt = elmt * (rowIndex - i + 1) / i;
                res.push_back(elmt);
            }
            return res;
        }

Log in to reply
 

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