赎金信383

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

//赎金信383
public class RansomNote383 {
public static void main(String[] args) {
if (new Solution().canConstruct("bb","ba")){
System.out.println("OK");
} else{
System.out.println("NO");
}
}
}
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
int[] arr = new int[26];
for (char item : magazine.toCharArray()) {
arr[item - 'a']++;
}
for (char item : ransomNote.toCharArray()) {
arr[item - 'a']--;
}
for (int item : arr) {
if (item < 0) {
return false;
}
}
return true;

}
}