• [LeetCode] Pascal's Triangle


    Given numRows, generate the first numRows of Pascal's triangle.

    For example, given numRows = 5,
    Return

    [
         [1],
        [1,1],
       [1,2,1],
      [1,3,3,1],
     [1,4,6,4,1]
    ]

    模拟题。
     1 class Solution {
     2 private:
     3     vector<vector<int> > ret;
     4 public:
     5     vector<vector<int> > generate(int numRows) {
     6         // Start typing your C/C++ solution below
     7         // DO NOT write int main() function
     8         ret.clear();
     9         
    10         for(int i = 0; i < numRows; i++)
    11         {
    12             if (i == 0)
    13             {
    14                 vector<int> a;
    15                 a.push_back(1);
    16                 ret.push_back(a);
    17             }
    18             else
    19             {
    20                 vector<int> a;
    21                 for(int j = 0; j <= i; j++)
    22                     if (j == 0)
    23                         a.push_back(ret[i-1][j]);
    24                     else if (j == i)
    25                         a.push_back(ret[i-1][j-1]);
    26                     else
    27                         a.push_back(ret[i-1][j-1] + ret[i-1][j]);
    28                 ret.push_back(a); 
    29             }
    30         }
    31         
    32         return ret;
    33     }
    34 };
  • 相关阅读:
    jQuery(四)
    jQuery(三)
    jQuery(二)
    jQuery(一)
    JS(四)
    JS(三)
    JS(二)
    类似openDialog的弹窗
    vue的异步组件按需加载
    vue实现点击、滑动右侧字母对应各个城市
  • 原文地址:https://www.cnblogs.com/chkkch/p/2767701.html
Copyright © 2020-2023  润新知