LintCode 54 比较字符串
来源:互联网 发布:钱宝数据助手怎么退订 编辑:程序博客网 时间:2024/05/21 01:30
题目:compareStrings
要求:
比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母
注意事项
在 A 中出现的 B 字符串里的字符不需要连续或者有序。
样例:
给出 A = “ABCD” B = “ACD”,返回 true
给出 A = “ABCD” B = “AABC”, 返回 false
算法要求:
无
解题思路:
先将A里的字符存到a数组进行计数。
接着遍历B中的字符,进行负计数即可。
算法如下:
bool compareStrings(string A, string B) { // write your code here char a[256] = {0}; if (A.size() < B.size()) { return false; } for (int i = 0; A[i] != '\0'; i++) { a[A[i]]++; } for (int j = 0; B[j] != '\0'; j++) { if (a[B[j]] == 0) { return false; } a[B[j]]--; } return true; }
0 0
- LintCode 54 比较字符串
- Lintcode(2)-比较字符串
- LintCode比较字符串
- Lintcode 比较字符串
- lintcode-比较字符串-55
- LintCode 比较字符串
- Lintcode 比较字符串
- LintCode-比较字符串
- lintcode刷题--比较字符串
- LintCode 比较字符串
- Lintcode-比较字符串
- lintcode ----比较字符串
- LintCode之比较字符串
- lintCode 55:比较字符串
- LintCode : 比较字符串
- Lintcode 比较字符串
- LintCode-比较字符串
- lintcode -- 比较字符串
- 测试nginx配置文件是否生效的简便方法
- linux/centos安装nginx常见错误及解决办法
- zzuli 2130: hipercijevi bfs+输入输出外挂 (2017轻工业校赛 )
- Linux下Nginx+Tomcat整合的安装与配置
- 判断是否为完全二叉树
- LintCode 54 比较字符串
- Prometheus 实战于源码分析之scrape
- 人手一支笔:ThreadLocal
- caffe调用之前的权重和接着断点继续训练
- 344. Reverse String(C语言)
- 解决Mysql错误Too many connections的方法
- AngularJS控制器
- Mybatis 配置出现元素类型为 "configuration" 的内容必须匹配 "(properties?,settings?,typeAliases?,typeHandlers?,objectF
- ubuntu mysql 启动失败