比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是大写字母
题目链接
public class Solution {
/**
* @param A : A string includes Upper Case letters
* @param B : A string includes Upper Case letter
* @return : if string A contains all of the characters in B return true else return false
*/
public boolean compareStrings(String A, String B) {
int[] aCount = new int[26];
int[] bCount = new int[26];
for(int i = 0; i < A.length(); ++i) aCount[A.charAt(i) - 'A']++;
for(int i = 0; i < B.length(); ++i) bCount[B.charAt(i) - 'A']++;
for(int i = 0; i < 26; ++i) {
if(bCount[i] > aCount[i]) return false;
}
return true;
}
}