Compare Strings

 1 public class Solution {
 2     /**
 3      * @param A : A string includes Upper Case letters
 4      * @param B : A string includes Upper Case letter
 5      * @return :  if string A contains all of the characters in B return true else return false
 6      */
 7     public boolean compareStrings(String A, String B) {
 8         // write your code here
 9         if (A.length() < B.length()){
10             return false;
11         }
12         char[] charA = A.toCharArray();
13         char[] charB = B.toCharArray();
14         int[] nums = new int[27];
15         int index;
16         for (int i = 0; i < A.length(); i++){
17             index = charA[i] - 'A';
18             nums[index]++;
19         }
20         for (int j = 0; j < B.length(); j++){
21             index = charB[j] - 'A';
22             nums[index]--;
23             if (nums[index] < 0){
24                 return false;
25             }
26         }
27         return true;
28     }
29 }
原文地址:https://www.cnblogs.com/CuiHongYu/p/7064553.html