比较字符串

class Solution {
public:
/**
* @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
*/
bool compareStrings(string A, string B) {
// write your code here
if(B.size()>A.size())
return false;

    int letters[26];
    memset(letters,0,sizeof(letters));
    for(int i=0;i<A.size();i++){
        letters[A[i]-'A']++;
    }
    for(int i=0;i<B.size();i++){
        if(letters[B[i]-'A']<=0)
           return false;
        else{
           letters[B[i]-'A']--;
        }
    }
    return true;
}

};

posted @ 2017-08-22 02:11  逸文皓  阅读(101)  评论(0)    收藏  举报