intminFallingPathSum(vector<vector<int>>& matrix){ int n = matrix.size(); vector<vector<int>> f(n, vector<int>(n)); for (int i = 0; i < n; i ++) { f[0][i] = matrix[0][i]; }
for (int i = 1; i < n; i ++) { for (int j = 0; j < n; j ++) { if (j == 0) f[i][j] = min(f[i - 1][j], f[i - 1][j + 1]) + matrix[i][j]; elseif (j == n - 1) f[i][j] = min(f[i - 1][j - 1], f[i - 1][j]) + matrix[i][j]; else f[i][j] = min({f[i - 1][j - 1], f[i - 1][j], f[i - 1][j + 1]}) + matrix[i][j]; } } int minn = 0x3f3f3f3f; for (int i = 0; i < n; i ++) { minn = min(minn, f[n - 1][i]); } return minn; }
intmaxProfit(vector<int>& prices){ int maxn = 0, minn = 0x3f3f3f3f; for (int i = 0; i < prices.size(); i ++) { minn = min(minn, prices[i]); maxn = max(maxn, prices[i] - minn); } return maxn; }