【leetcode周赛记录】第78场双周赛+第293场周赛记录
赛后个人排名
赛题分析总结
第78场双周赛
5299.找到一个数字的K美丽值
class Solution {
public:
// 模拟即可
int divisorSubstrings(int num, int k) {
string s = to_string(num);
int result{};
int n = s.size();
for(int i{};i<n-k + 1;++i){
int tempNum{};
for(int j{};j<k;++j){
tempNum = tempNum*10 + (s[i+j]-'0');
}
if(tempNum != 0 && num % tempNum == 0) result++;
}
return result;
}
};
6067.分割数组的方案数
class Solution {
public:
// 考察前缀和
int waysToSplitArray(vector<int>& nums) {
int n = nums.size();
vector<long long> pre(n+1);
for(int i{};i<n;++i){
pre[i+1] = pre[i] + nums[i];
}
long long allSums = pre[n];
int result{};
for(int i{};i<n-1;++i){
long long sum1 = pre[i+1];
long long sum2 = allSums - sum1;
if(sum1 >= sum2) result++;
}
return result;
}
};
6068.毯子覆盖的最多白色砖块数
// 未AC
// 后续进行双指针的专项复习、训练以及总结
6069.最大波动的子字符串
直接忽略
第293场周赛
5234.移除字母异位词后的结果数组
class Solution {
public:
// 模拟求解
vector<string> removeAnagrams(vector<string>& words) {
int n = words.size();
vector<int> need1(26);
vector<int> need2(26);
for(int i{};i<words[0].size();++i){
need1[words[0][i] - 'a']++;
}
for(int i{1};i<n;++i){
for(int j{};j<words[i].size();++j){
need2[words[i][j] - 'a']++;
}
while(need1 == need2 && i < n){
words.erase(words.begin()+i);
need2.clear();
need2.resize(26,0);
--n;
string x = words[i];
for(int j{};j<x.size();++j){
need2[x[j] - 'a']++;
}
}
need1 = need2;
need2.clear();
need2.resize(26,0);
}
return words;
}
};
6064.不含特殊楼层的最大连续楼层数
class Solution {
public:
// 贪心求解
int maxConsecutive(int bottom, int top, vector<int>& special) {
if(special.size() == 0){
return top-bottom+1;
}
sort(special.begin(),special.end());
int result{};
int curCount{};
for(int i{};i< special.size();++i){
int newTop = special[i];
curCount = newTop - bottom;
if(curCount > result){
result = curCount;
}
bottom = newTop+1;
}
int x = top - bottom +1;
return max(result,x);
}
};
6065.按位与结果大于零的最长组合
class Solution {
public:
int largestCombination(vector<int>& candidates) {
// 计算从低到高第 k 个二进制位数值为 1 的元素个数
auto maxlen = [&](int k) -> int {
int res = 0;
for (int num: candidates) {
if (num & (1 << k)) {
++res;
}
}
return res;
};
int res = 0;
for (int i = 0; i < 24; ++i) {
// 遍历二进制位
res = max(res, maxlen(i));
}
return res;
}
};
6066.统计区间中的整数数目
第四题暂不考虑
反思总结
个人情况
第27、28次参加leetcode竞赛;
总计得到过6次12分,13次7分,9次3分;
后续改进
- 双指针的专项复习、训练以及总结系统训练,总结
- 位运算的专项复习、训练以及总结系统训练,总结