public class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
int[] ransomNum = new int[256];
int[] magNum = new int[256];
for (int i = 0; i < 256; i++) {
ransomNum[i] = magNum[i] = 0;
}
for (int i = 0; i < ransomNote.length(); i++) {
ransomNum[(int)ransomNote.charAt(i)]++;
}
for (int i = 0; i < magazine.length(); i++) {
magNum[(int)magazine.charAt(i)]++;
}
for (int i = 0; i < 256; i++) {
if (ransomNum[i] > magNum[i]) return false;
}
return true;
}
}
相关文章
- LeetCode之404. Sum of Left Leaves
- 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】
- 【leetcode 简单】 第八十八题 猜数字大小
- #yyds干货盘点# LeetCode程序员面试金典:无重复字符串的排列组合
- #yyds干货盘点# LeetCode面试题:最长回文子串
- LeetCode——Pascal's Triangle
- ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java
- leetcode[60] Rotate List
- #yyds干货盘点# LeetCode面试题:寻找两个正序数组的中位数
- 【leetcode】Reorder List (middle)