LeetCode题目,杨辉三角Ⅱ,O(k)空间递推解法
class Solution { public: vector<int> getRow(int rowIndex) { vector<int> ans(rowIndex+1,0); int temp=0; for(int i=0;i<=rowIndex;++i) { for(int j=0;j<=i;++j) { if(j==0||j==i) { ans.at(j)=1; temp=ans.at(j); } else { ans.at(j)+=temp; temp=ans.at(j)-temp; } } } return ans; } };
                    
                
                
            
        
浙公网安备 33010602011771号