LintCode-第55题 比较字符串
来源:互联网 发布:财务战略矩阵案例 编辑:程序博客网 时间:2024/05/22 14:15
描述:
比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母
注意事项
在 A 中出现的 B 字符串里的字符不需要连续或者有序。
样例:
代码实现: 给出 A = "ABCD"
B = "ACD"
,返回 true
给出 A = "ABCD"
B = "AABC"
, 返回 false
public boolean compareStrings(String A, String B) { // write your code here char ch_A[] = A.toCharArray();//获得a中的字符数组char ch_B[] = B.toCharArray();//获得b中的字符数组int len_A = ch_A.length; int len_B = ch_B.length; int a[] = new int[len_A];//记录a中每个字符出现的次数 int b[] = new int[len_B];//记录b中每个字符出现的次数 if(len_A<len_B){//b中的字符数不可能小于a中的字符数 return false; } for(int i=0;i<ch_B.length;i++){ int ca = getCharNumber(ch_A,ch_B[i]); int cb = getCharNumber(ch_B,ch_B[i]); if(ca<cb){ return false; } } return true; } //计算字符ch在数组str中的个数 private int getCharNumber(char str[],char ch){int len = str.length;int count=0; for(int i = 0; i< len;i++){if(str[i]==ch){count++; } } return count;}
0 0
- LintCode-第55题 比较字符串
- lintcode-比较字符串-55
- lintCode 55:比较字符串
- Lintcode(2)-比较字符串
- LintCode比较字符串
- Lintcode 比较字符串
- LintCode 比较字符串
- Lintcode 比较字符串
- LintCode-比较字符串
- lintcode刷题--比较字符串
- LintCode 比较字符串
- Lintcode-比较字符串
- lintcode ----比较字符串
- LintCode之比较字符串
- LintCode : 比较字符串
- Lintcode 比较字符串
- LintCode 54 比较字符串
- LintCode-比较字符串
- 【leetcode】Missing Number
- Cuda里面的Texture Memory
- javaee之Spring的AOP案例
- 多态的好处
- 多表查询
- LintCode-第55题 比较字符串
- linux下进程的状态,创建,替换,等待,终止
- Linux jdk卸载并安装升级
- iOS—如何申请苹果公司开发者账号流程详细图文介绍(包括邓白氏编码的申请方法详细介绍)
- Android5.0后出现的新错误:fatal error 11 fault addr
- 国际化-android
- [USACO]1.2.2Milking Cows
- *[Lintcode]Convert Sorted List to Balanced BST
- JSP基础+==filter+struts(.xml配置)