利用一个长度为26的数组记录magazine中每个字母出现的次数(递增),再与ransom note中每个字母出现的次数进行对比(递减)即可。 #include <string> using std::string; class Solution { public: bool canConstruct(string ransomNote, string magazine) { int a[26] =
LeetCode 383. Ransom Note (赎金信) 题目 链接 https://leetcode.cn/problems/ransom-note/ 问题描述 给你两个字符串:ransomNote 和 magazine ,判断 ransomNote 能不能由 magazine 里面的字符构成。 如果可以,返回 true ;否则返回 false 。 magazine 中的每个字符只能在 ransomNote
class Solution { public boolean canConstruct(String ransomNote, String magazine) { Boolean ans=true; int[] a=new int[26]; int[] b=new int[26]; for(int i=0;i<ransomNote.length();i++) { a[ransomNote.charAt
class Solution { public boolean canConstruct(String ransomNote, String magazine) { int[] letter1 = new int[123]; int[] letter2 = new int[123]; for (int i = 0; i < ransomNote.length(); i++){ letter1[ransom
Problem: Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false. Each letter in
每天一道编程题题目描述样例python解法C语言解法 题目描述 Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ;