LeetCode第 83 场双周赛

总结:

从今天开始继续更新周赛,包括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;
    }
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Shirandexiaowo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值