题解 | #杨辉三角-ii#

杨辉三角-ii

https://www.nowcoder.com/practice/a60ee4a1c8a04c3a93f1de3cf9c16f19

#include <vector>
class Solution {
public:
    /**
     * 
     * @param rowIndex int整型 
     * @return int整型vector
     */
    vector<int> getRow(int rowIndex) {
        vector<int> yhsj(rowIndex+1);
        for(int i=0;i<=rowIndex;i++)
        {
          yhsj[i]=cmn(i,rowIndex);
        }
       return yhsj;
    }
    
    int cmn(int n,int m)
    {
        if(n==0||n==m)
        return 1;
        long int ncj=1;
        long int mcj=1;
       for(int i=1;i<=n;i++)
       {
          mcj*=(m-i+1);
          ncj*=i;
          if(mcj%ncj==0)
          {
            mcj/=ncj;
            ncj=1;
          }
       }
       return mcj;
    }
};

全部评论

相关推荐

大摆哥:刚好要做个聊天软件,直接让你帮他干活了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务