当前位置:网站首页>LeetCode第 83 场双周赛
LeetCode第 83 场双周赛
2022-07-27 23:56:00 【Shirandexiaowo】
总结:
从今天开始继续更新周赛,包括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;
}
};
边栏推荐
猜你喜欢

N32L43x Flash读\写\擦除操作总结

Can ordinary equipment access TSN time sensitive network?

Brushes and brushes

Niuke net question brushing training (III)

HCIP第十二天笔记

Sort out SQL performance optimization and collect classics!

MPLS 隧道实验

周报、月报有多折磨人?万能报表模板建议收藏!(附模板)

暴雪《暗黑破坏神 4》PS5 / PS4 测试版添加到 PlayStation 数据库

Flink's real-time data analysis practice in iFLYTEK AI marketing business
随机推荐
GBase 8c 备份控制函数(四)
IIC read / write eefprom
docker 本地搭建mysql主从
三舅的故事
Dart 代码注释和文档编写规范
梳理 SQL 性能优化,收藏经典!
qt 设置图标
FreeRTOS内核小结
阿虎的故事
软件测试面试题:性能测试指标有哪些?
实现OCR语言识别Demo(二)- 图片及识别内容的展现和交互
Leetcode 2351. the first letter that appears twice
Linux系统彻底删除Mysql
负载均衡SLB
VLAN实验
现货白银如何计算盈亏
Qlib教程——基于源码(二)本地数据保存与加载
物企大变局时代,SRM供应商采购系统助力企业打造物业采购数字化标杆
Content bypass sharing
【样式集合1】tab 栏