118. 杨辉三角
class Solution {
public:vector<vector<int>> generate(int numRows) {// 定义二维数组vector<vector<int>> num(numRows);for(int i=0;i<numRows;i++){//这里是给内层vector定义大小。默认是0,这里n是个数,不是值num[i].resize(i + 1);num[i][0] = num[i][i] = 1;for (int j = 1; j < i; ++j) {num[i][j] = num[i - 1][j] + num[i - 1][j - 1];}}return num;}
};
119. 杨辉三角 II
class Solution {
public:vector<int> getRow(int rowIndex) {vector<vector<int>> num(rowIndex + 1);vector<int> num1;for (int i = 0; i <= rowIndex; ++i) {num[i].resize(i + 1);num[i][0] = num[i][i] = 1;for (int j = 1; j < i; ++j) {num[i][j] = num[i - 1][j] + num[i - 1][j - 1];if (i == rowIndex) {num1.push_back(num[i][j]);}}}if (rowIndex > 0) {num1.insert(num1.begin(), num[rowIndex][0]);}num1.push_back(num[rowIndex][rowIndex]);return num1;}
};
661. 图片平滑器
有思路但没写出来(复习)
class Solution {
public:vector<vector<int>> imageSmoother(vector<vector<int>>& img) {int m = img.size(), n = img[0].size();vector<vector<int>> ret(m, vector<int>(n));for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {int num = 0, sum = 0;for (int x = i - 1; x <= i + 1; x++) {for (int y = j - 1; y <= j + 1; y++) {if (x >= 0 && x < m && y >= 0 && y < n) {num++;sum += img[x][y];}}}ret[i][j] = sum / num;}}return ret;}
};
598. 范围求和 II
class Solution {
public:int maxCount(int m, int n, vector<vector<int>>& ops) {int mina = m, minb = n;for (const auto& op: ops) {mina = min(mina, op[0]);minb = min(minb, op[1]);}return mina * minb;}
};