美文网首页Lintcode
Lintcode55 Compare Strings solut

Lintcode55 Compare Strings solut

作者: 代码码着玩 | 来源:发表于2017-04-24 23:10 被阅读18次

【题目描述】

Compare two strings A and B, determine whether A contains all of the characters in B.The characters in string A and B are all Upper Case letters.

Notice:The characters of B in A are not necessary continuous or ordered.

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

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

【题目链接】

www.lintcode.com/en/problem/compare-strings/

【题目解析】

题目意思是问B中的所有字符是否都在A中,而不是单个字符。比如B="AABC"包含两个「A」,而A="ABCD"只包含一个「A」,故返回false.

既然不是类似strstr那样的匹配,直接使用两重循环就不太合适了。题目中另外给的条件则是A和B都是全大小单词,理解题意后容易想到的方案就是先遍历A和B统计各字符出现的频次,然后比较频次大小即可。嗯,祭出万能的哈希表。

【参考答案】

www.jiuzhang.com/solutions/compare-strings/

相关文章

网友评论

    本文标题:Lintcode55 Compare Strings solut

    本文链接:https://www.haomeiwen.com/subject/jwjvnttx.html