0%

leetcode_biweekly_contest_28

5420. 商品折扣后的最终价格

思路:
两重循环直接遍历即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
vector<int> finalPrices(vector<int>& prices) {
vector<int> res;
for(int i=0;i<prices.size();++i){
int tmp =prices[i];
for(int j=i+1;j<prices.size();++j){
if(prices[j] <= tmp){
tmp -= prices[j];
break;
}
}
res.push_back(tmp);
}
return res;
}
};

5422. 子矩形查询

思路:
简答直接赋值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class SubrectangleQueries {
public:
vector<vector<int>> res;
SubrectangleQueries(vector<vector<int>>& rectangle) {
res = rectangle;
}

void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {
for(int i=row1;i<=row2;++i){
for(int j=col1; j<= col2;++j){
res[i][j] = newValue;
}
}
}

int getValue(int row, int col) {
return res[row][col];
}
};

思路: