总结:
从今天开始继续更新周赛,包括cf、lc和atcoder,夏令营目前还算顺利,不过暂时还没有确定去哪。等9月份知道的时候再告诉大家。
这场周赛难度比较简单,但是比较考验数据结构的理解
6128. 最好的扑克手牌
class Solution:
def bestHand(self, ranks: List[int], suits: List[str]) -> str:
if len(set(suits)) == 1:
return 'Flush'
for i in ranks:
if ranks.count(i) >= 3:
return 'Three of a Kind'
for i in ranks:
if ranks.count(i) == 2:
return 'Pair'
return 'High Card'
2348. 全 0 子数组的数目
class Solution {
public:
long long zeroFilledSubarray(vector<int>& nums) {
long long ans = 0;
for (int i = 0; i < nums.size(); i ++ ) {
if (nums[i]) continue;
int j = i;
while (j < nums.size() && nums[j] == 0) j ++ ;
int c = j - i;
ans += 1ll * (1 + c) * c / 2;
i = j;
}
return ans;
}
};
2349. 设计数字容器系统
class NumberContainers {
public:
map<int, set<int>> id;
map<int, int> mp;
NumberContainers() {
}
void change(int index, int number) {
if (!mp[index]) {
mp[index] = number;
id[number].insert(index);
}
else {
int t = mp[index];
id[t].erase(index);
mp[index] = number;
id[number].insert(index);
}
}
int find(int number) {
if (id[number].size() == 0)
return -1;
else return *id[number].begin();
}
};
/**
* Your NumberContainers object will be instantiated and called as such:
* NumberContainers* obj = new NumberContainers();
* obj->change(index,number);
* int param_2 = obj->find(number);
*/
2350. 不可能得到的最短骰子序列
class Solution {
public:
int shortestSequence(vector<int>& rolls, int k) {
set<int> s;
int ans = 0;
for (int u : rolls) {
s.insert(u);
if (s.size() == k) {
s.clear();
ans ++;
}
}
return ans + 1;
}
};

本周分享了编程挑战,涉及数据结构的6128题解法(扑克手牌)、2348题的全0子数组计数和2349题数字容器设计。通过实例讲解了如何利用flush、三张同花、对子等策略判断最佳手牌,以及零填充子数组的高效计算。
609

被折叠的 条评论
为什么被折叠?



