LeetCode: Ransom Note

 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;
}
}
上一篇:python argparse用法总结


下一篇:js 获取控制台的错误信息