C++ O(k) space solution


  • 0
     vector<int> getRow(int rowIndex) {
            vector<int> res;
            res.push_back(1);
            if(rowIndex==0) return res;
            res.push_back(1);
            while(rowIndex>1){
                int tmp1,tmp2=1;
                for(int i=1;i<res.size();i++){
                    tmp1=res[i];
                    res[i]=tmp2+res[i];
                    tmp2=tmp1;
                }
                res.push_back(1);
                rowIndex--;
            }
            return res;
        }
    

Log in to reply
 

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