比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母
public class Solution { /** * @param A: A string * @param B: A string * @return: if string A contains all of the characters in B return true else return false */ public boolean compareStrings(String A, String B) { // write your code here 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; } }