4 lines O(k) C++ clean self-explanatory code


  • 0
    X
    class Solution {
    public:
        vector<int> getRow(int rowIndex) {
            vector<int> ans(rowIndex+1,1);
            for(int i=1;i<rowIndex+1;i++)
                ans[i]=(long long)ans[i-1]*(rowIndex+1-i)/i;
            return ans;
        }
    };
    

Log in to reply
 

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