周赛补题.

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

 力扣周赛第一题:

采用哈希表来处理

class Solution {
public:
    string greatestLetter(string s) {
        vector<int> cnt(128);
        for (auto x : s) cnt[x]++;
        string ans;
        for (int i = 65; i <= 90; ++i) {
            if (cnt[i] && cnt[i+32]) ans = i;
        }
        return ans;
    }
};

力扣周赛第二题:

https://leetcode.cn/problems/sum-of-numbers-with-units-digit-k/

每个数可以表示成10的倍数加上k的形式,

由于这n个数都以k结尾,那么num−nk必须是10的倍数。

从小到大枚举n,找到第一个满足num−nk是10的倍数的n。

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;
    }
};

acwing周赛第一题:

https://www.acwing.com/problem/content/4485/

 将每一种数字归类,然后每一个数字有几个就加入几个集合。所以答案就是数字种类数量最多的数量。

#include<bits/stdc++.h>
using namespace std;
const int N=109;
int n,a[N];
int main ()
{
    cin>>n;
    for (int i=1;i<=n;++i)
        cin>>a[i];
    int cnt[N]={};
    for (int i=1;i<=n;++i)
        cnt[a[i]]++;
    cout<<*max_element(cnt,cnt+101);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值