LintCode 55. 比较字符串
来源:互联网 发布:淘宝上电子发票在哪里 编辑:程序博客网 时间:2024/06/11 08:34
比较两个字符串A和B,确定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[] count = new int[128]; for(int i=0;i<A.length();i++){ count[A.charAt(i)]++; } for(int i=0;i<B.length();i++){ if(count[B.charAt(i)]!=0){ count[B.charAt(i)]--; }else{ return false; } } return true; }}给出 A =
"ABCD"
B ="ACD"
,返回true
给出 A =
"ABCD"
B ="AABC"
, 返回false
使用桶排,将A字符串的每一个字符放入相应的桶中,没有一个字符在相应的字符加一。
循环B字符串,桶中有相应的字符则--,等于0则不包括,返回false;
阅读全文
0 0
- LintCode 55. 比较字符串
- LintCode(容易)55.比较字符串
- Lintcode(2)-比较字符串
- LintCode比较字符串
- Lintcode 比较字符串
- lintcode-比较字符串-55
- LintCode 比较字符串
- Lintcode 比较字符串
- LintCode-比较字符串
- lintcode刷题--比较字符串
- LintCode 比较字符串
- Lintcode-比较字符串
- lintcode ----比较字符串
- LintCode之比较字符串
- lintCode 55:比较字符串
- LintCode : 比较字符串
- Lintcode 比较字符串
- LintCode 54 比较字符串
- 4-1 复数类的运算符重载
- 简单电路实验
- LINUX下的C学生信息管理系统
- 让爱随时随地
- 如何优化MySQL insert性能
- LintCode 55. 比较字符串
- B
- [python]
- Android通过查询数据库手机联系人信息
- 问题解决
- 第三个
- 数据库内置函数2-数值函数,时间函数,null函数
- 技术人成长要如何思考
- H5和CSS3中部分新增标签