lintcode-比较字符串-55

来源:互联网 发布:ubuntu debian fedora 编辑:程序博客网 时间:2024/06/10 06:15

比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母

您在真实的面试中是否遇到过这个题?
样例

给出 A = "ABCD" B = "ACD",返回 true

给出 A = "ABCD" B = "AABC", 返回 false

注意 在 A 中出现的 B 字符串里的字符不需要连续或者有序


class Solution {public:       bool compareStrings(string A, string B) {        // write your code here        map<char,int> check;        for(auto e:A)            ++check[e];        for(auto e:B){            if(--check[e]<0)                return false;        }        return true;            } };


0 0
原创粉丝点击