Leetcode—383.赎金信【简单】

2023每日刷题(五十)

Leetcode---383.赎金信

实现代码

cpp 复制代码
class Solution {
public:
    int arr[26] = {0};
    int arr2[26] = {0};
    bool canConstruct(string ransomNote, string magazine) {
        int len = ransomNote.size();
        int len2 = magazine.size();
        for(int i = 0; i < len; i++) {
            int idx = ransomNote[i] - 'a';
            arr[idx] += 1;
        }
        for(int i = 0; i < len2; i++) {
            int idx = magazine[i] - 'a';
            arr2[idx] += 1;
        }
        for(int i = 0; i < 26; i++) {
            if(arr[i] > arr2[i]) {
                return false;
            }
        }
        return true;
    }
};

运行结果


之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
Better Rose20 分钟前
【数模国奖冲刺】备赛过程中的常见问题
经验分享·数学建模·数模国赛
浮灯Foden24 分钟前
算法-每日一题(DAY13)两数之和
开发语言·数据结构·c++·算法·leetcode·面试·散列表
淡海水37 分钟前
【原理】Struct 和 Class 辨析
开发语言·c++·c#·struct·class
西工程小巴1 小时前
实践笔记-VSCode与IDE同步问题解决指南;程序总是进入中断服务程序。
c语言·算法·嵌入式
Tina学编程1 小时前
48Days-Day19 | ISBN号,kotori和迷宫,矩阵最长递增路径
java·算法
Moonbit1 小时前
MoonBit Perals Vol.06: MoonBit 与 LLVM 共舞 (上):编译前端实现
后端·算法·编程语言
执子手 吹散苍茫茫烟波2 小时前
leetcode415. 字符串相加
java·leetcode·字符串
青草地溪水旁2 小时前
UML函数原型中stereotype的含义,有啥用?
c++·uml
青草地溪水旁2 小时前
UML函数原型中guard的含义,有啥用?
c++·uml
百度Geek说3 小时前
第一!百度智能云领跑视觉大模型赛道
算法