- 🧛♂️个人主页:杯咖啡
- 💡进步是今天的活动,明天的保证!
- ✨目前正在学习:SSM框架,算法刷题
- 🙌牛客网,刷算法过面试的神级网站,用牛客你也牛。 👉免费注册和我一起学习刷题👈
- 🐳希望大家多多支持🥰一起进步呀!
- 😎The man who fears losing has already lost.
怕输的人已经输了。 - 《权力的游戏》
1.分发饼干 https://leetcode.cn/problems/assign-cookies/
2.心算挑战 https://leetcode.cn/problems/uOAnQW/
3.保持城市天际线 https://leetcode.cn/problems/max-increase-to-keep-city-skyline/
4.Shoe Shuffling https://codeforces.com/problemset/problem/1691/B
1、
2、
3、
class Solution {
public int maxIncreaseKeepingSkyline(int[][] grid) {
int n = grid.length;
int[] rowMax = new int[n];
int[] colMax = new int[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
rowMax[i] = Math.max(rowMax[i], grid[i][j]);
colMax[j] = Math.max(colMax[j], grid[i][j]);
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ans += Math.min(rowMax[i], colMax[j]) - grid[i][j];
}
}
return ans;
}
}