周赛补题

力扣285场

第一题

力扣https://leetcode.cn/problems/greatest-english-letter-in-upper-and-lower-case/

遍历+数组计数

class Solution {
public:
    int A[27],a[27];
    string greatestLetter(string s) {
        for(int i=0;i<=26;i++){A[i]=0,a[i]=0;}
        
        for(char ch:s){
            if(ch < 'a') A[ch-'A']++;
            else a[ch-'a']++;
        }
        string ss="";
        for(int i = 25;i>=0;i--){
            if(A[i]&&a[i]) {ss.push_back('A'+i);return ss;}
        }
        return "";
    }
};

也可以使用哈希表来处理

class Solution{
public:
    string greattestLetter(string s){
        unordered_set<char> S;
        for(auto c:s)S.insert(c);
        for(char i='z';i>='a';i--)
        {
            if(S.count(i)&&S.count(i-32)){
                return string(1,i-32);
            }
        }
    }
    return "";
}

第二题

力扣https://leetcode.cn/problems/sum-of-numbers-with-units-digit-k/每个数都可以表示成10的倍数以上k的形式,且num-nk一定是10的倍数

class Solution {
public:
    int minimumNumbers(int num, int k) {
        if (num == 0) return 0;
        for (int n = 1; n <= 10 && num - k * n >= 0; ++n)
            if ((num - k * n) % 10 == 0) return n;
        return -1;
    }
};

Acwing56场

第一题

4482. 分组 - AcWing题库高质量的算法题库https://www.acwing.com/problem/content/4485/用数组统计每个数出现次数,取最大值得出答案

#include <bits/stdc++.h>
using namespace std;


const int N=110;

int n;
int a[N];

int main
{
    cin>>n;
    int res=0;
    while(n--)
    {
        int x;
        cin>>x;
        res=max(res,++cnt[x]);
    }
    cout<<res;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值