【LeetCode热题100】【动态规划】杨辉三角

题目链接:118. 杨辉三角 - 力扣(LeetCode)

弄个二维数组,每个数是它左上方和右上方的数的和

class Solution {
public:
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> ans(numRows);
        for (int i = 0; i < numRows; i++) {
            ans[i].resize(i + 1);
            ans[i][0] = ans[i][i] = 1;
            for (int j = 1; j < i; j++) {
                ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j];
            }
        }
        return ans;
    }
};

相关推荐

  1. LeetCode100】【动态规划三角

    2024-04-07 10:26:03       40 阅读
  2. leetcode-三角

    2024-04-07 10:26:03       65 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-07 10:26:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-07 10:26:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-07 10:26:03       82 阅读
  4. Python语言-面向对象

    2024-04-07 10:26:03       91 阅读

热门阅读

  1. python+ opencv(Mat)——笔记

    2024-04-07 10:26:03       33 阅读
  2. leetcode594-Longest Harmonious Subsequence

    2024-04-07 10:26:03       32 阅读
  3. redis bigKey问题

    2024-04-07 10:26:03       37 阅读
  4. Docker 中运行一个容器并查看其日志

    2024-04-07 10:26:03       38 阅读
  5. flinkCDC

    flinkCDC

    2024-04-07 10:26:03      30 阅读
  6. leetcode599-Minimum Index Sum of Two Lists

    2024-04-07 10:26:03       25 阅读