zoukankan      html  css  js  c++  java
  • Pascal's Triangle

    class Solution {
    public:
        vector<vector<int>> generate(int numRows) {
            vector<vector<int>>result;
            if(numRows<=0)
            return result;
            int n = numRows;
          for(int i= 0;i<n;i++)
          {
               vector<int>temp;
               for(int j=0;j<=i;j++)
               {if(j==0||j==i)//技巧就是这里的第一个和最后都为1,用该语句
                    temp.push_back(1);
               else
                    temp.push_back(result[i-1][j-1]+result[i-1][j]);
               }
              result.push_back(temp);
          }
          return result; 
        }
    };

  • 相关阅读:
    HDU 3537
    POJ 1175
    POJ 1021 人品题
    POJ 2068
    POJ 2608
    POJ 2960
    poj 1635
    ustc 1117
    ural 1468
    数字游戏
  • 原文地址:https://www.cnblogs.com/gofighting/p/5036345.html
Copyright © 2011-2022 走看看