Leetcode 第 293 场周赛

题目链接

5234. 移除字母异位词后的结果数组

class Solution {
public:
    vector<string> removeAnagrams(vector<string>& s) {
        vector<string>res;
        res.push_back(s[0]);
        for(int i=1;i<s.size();i++)
        {
            string a=s[i-1],b=s[i];
            sort(a.begin(),a.end());
            sort(b.begin(),b.end());
            if(a==b)continue;
            res.push_back(s[i]);
        }
        return res;
    }
};

6064. 不含特殊楼层的最大连续楼层数

class Solution {
public:
    int maxConsecutive(int l, int r, vector<int>& a) {
        sort(a.begin(),a.end());
        int res=0;
        res=max(a[0]-l,r-a.back());
        for(int i=1;i<a.size();i++)
            res=max(a[i]-a[i-1]-1,res);
        return res;
    }
};

6065. 按位与结果大于零的最长组合

class Solution {
public:
    int largestCombination(vector<int>& a) {
        int res=0;
        for(int i=0;i<24;i++)
        {
            int cnt=0;
            for(auto x : a)
            {
                if(x>>i&1)
                    cnt++;
            }
            res=max(res,cnt);
        }
        return res;
    }
};

6066. 统计区间中的整数数目

class CountIntervals {
public:
    int cnt;
    set<pair<int,int>>s;
    CountIntervals() {
        cnt=0;
    }
    
    void add(int left, int right) {
        auto it=s.lower_bound({left,left});
        if(it!=s.begin())it--;
        int l=left,r=right;
        while(it!=s.end()&&it->first<=right)
        {
            if(it->second<left-1)
            {
                it++;
                continue;
            }
            l=min(l,it->first);
            r=max(r,it->second);
            cnt-=it->second-it->first+1;
            s.erase(*it);
            it++;
        }
        s.insert({l,r});
        cnt+=r-l+1;
    }
    
    int count() {
        return cnt;
    }
};

/**
 * Your CountIntervals object will be instantiated and called as such:
 * CountIntervals* obj = new CountIntervals();
 * obj->add(left,right);
 * int param_2 = obj->count();
 */
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

_WAWA鱼_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值