【leetcode周赛记录】第294场周赛记录
赛后个人排名
赛题分析总结
第294场周赛
2278.字母在字符串中的百分比
class Solution {
public:
// 签到题
int percentageLetter(string s, char letter) {
float count{};
float n = s.size();
for(char c : s) if(letter == c) count++;
int result = (count*100/n);
return result;
}
};
2279.装满石头的背包的最大数量
class Solution {
public:
// 贪心即可
int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {
int n = capacity.size();
vector<int> need(n,0);
for(int i{};i<n;++i){
need[i] = capacity[i] - rocks[i];
}
sort(need.begin(),need.end());
int result{};
for(int i{};i<n;++i){
if(need[i] == 0){
result++;
}else{
while(additionalRocks >=need[i] && need[i] > 0){
additionalRocks-= need[i];
need[i] = 0;
}
if(need[i] == 0) result++;
}
}
return result;
}
};
2280.表示一个折线图的最少线段数
class Solution {
public:
// 求斜率不能用除法(导致最后一个用例就是过不去)
long long f1(vector<int>&a,vector<int>&b,vector<int>&c){
return (long long)(b[0]-a[0])*(c[1]-b[1]) - (long long)(b[1]-a[1])*(c[0]-b[0]);
}
int minimumLines(vector<vector<int>>& stockPrices) {
int result{0};
int n = stockPrices.size();
sort(stockPrices.begin(),stockPrices.end());
for(int i{};i<n-1;++i){
if(i == 0 || f1(stockPrices[i-1],stockPrices[i],stockPrices[i+1]) != 0){
result++;
}
}
return result;
}
};
2281.巫师的总力量和
第四题暂不考虑
反思总结
个人情况
第29次参加leetcode竞赛;
总计得到过6次12分,14次7分,9次3分;
后续改进
- 继续专项复习