LintCode 比较字符串
2015-12-09 17:17
375 查看
比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母
样例
给出 A =
=
给出 A =
=
注意
在 A 中出现的 B 字符串里的字符不需要连续或者有序。
样例
给出 A =
"ABCD"B
=
"ACD",返回
true
给出 A =
"ABCD"B
=
"AABC", 返回
false
注意
在 A 中出现的 B 字符串里的字符不需要连续或者有序。
public class Solution { /** * @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 */ public boolean compareStrings(String A, String B) { // write your code here int a[] = new int[26]; for(int i=0;i<A.length();i++) a[A.charAt(i) - 'A']++; for(int i=0;i<B.length();i++) if(a[B.charAt(i) - 'A'] <=0) return false; else { a[B.charAt(i) - 'A']--; } return true; } }
相关文章推荐
- VC6是怎么了
- android studio 导入项目(遇到到 的问题)
- iOS开发之多线程NSOperation
- 内存分析工具 MAT 的使用
- 网络层访问权限控制技术-ACL详解
- 读取xml文件中的数据示例
- spring mvc 415报错
- NSTimer
- 怎么把字符串的时间转换为想要的时间格式
- 43、BGP配置实验之聚合aggregate-address
- cocos2d-x 3.x相应键盘事件
- void 和 Void
- [javase学习笔记]-2.4 常量
- LibGDX 跨平台游戏开发基础教程(总目录)
- 欢迎使用CSDN-markdown编辑器
- python基础教程共60课-第20课命令行常用命令
- iOS框架介绍——N&O&P字头
- Android 实现MD5加密
- ui-router中resolve使用说明
- PC机与嵌入式开发板相互传输数据