Compare Strings
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.
For A = "ABCD", B = "ACD", return true.
For A = "ABCD", B = "AABC", return false.
分析:
用array记录每个字符在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) {
if (A == null & B != null) return false;
if (A == null && B == null) return true;
if (B == null) return true;
int[] charCounts = new int[];
for (int i = ; i < A.length(); i++) {
charCounts[A.charAt(i)]++;
}
for (int i = ; i < B.length(); i++) {
if (charCounts[B.charAt(i)] == ) {
return false;
}
charCounts[B.charAt(i)]--;
}
return true;
}
}
Compare Strings的更多相关文章
- LintCode 58: Compare Strings
LintCode 58: Compare Strings 题目描述 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是大写字母. 样例 给出A = "ABCD&q ...
- 【Leetcode_easy】1170. Compare Strings by Frequency of the Smallest Character
problem 1170. Compare Strings by Frequency of the Smallest Character 参考 1. Leetcode_easy_1170. Compa ...
- lintcode:Compare Strings 比较字符串
题目: 比较字符串 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母 样例 给出 A = "ABCD" B = "ACD" ...
- LeetCode.1170-比较字符串中最小字符的出现频率(Compare Strings by Frequency of the Smallest Char)
这是小川的第412次更新,第444篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第263题(顺位题号是1170).在一个非空字符串s上定义一个函数f(s),该函数计算s中最小字 ...
- 【leetcode】1170. Compare Strings by Frequency of the Smallest Character
题目如下: Let's define a function f(s) over a non-empty string s, which calculates the frequency of the ...
- [LC] 1170. Compare Strings by Frequency of the Smallest Character
Let's define a function f(s) over a non-empty string s, which calculates the frequency of the smalle ...
- 【LeetCode】1170. Compare Strings by Frequency of the Smallest Character 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双重循环 日期 题目地址:https://leetc ...
- Core Java Volume I — 3.6. Strings
3.6. StringsConceptually, Java strings are sequences of Unicode characters(Java的字符串是一个Unicode序列). Fo ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
随机推荐
- Excel如何查找名字重复的数据
来源于:http://jingyan.baidu.com/article/414eccf6091ff86b431f0aec.html Cokery今天在帮助同事整理数据的时候遇到了一个难题,就是在Ex ...
- 【POJ 3020】Antenna Placement(二分图匹配)
相当于用1*2的板覆盖给定的h*w的格子里的点,求最少的板.可以把格子相邻的分成两个集合,如下图,0为一个集合,1的为一个,也就是(行数+列数)为奇数的是一个集合,为偶数的为另一个集合.1010101 ...
- Spring POST
Spring POST+表单对象如果数据格式不正确,则页面直接报400.页面没有反应,烦啊
- Erlang第一课----基本变量
1.(in Erlang shell)A sequence of expressions must be terminated with a period followed by whitespace ...
- HDU 2896
传送门:HDU 2896 病毒侵袭 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- [工作积累] Google/Amazon平台的各种坑
所谓坑, 就是文档中没有标明的特别需要处理的细节, 工作中会被无故的卡住各种令人恼火的问题. 包括系统级的bug和没有文档化的限制. 继Android的各种坑后, 现在做Amazon平台, 遇到的坑很 ...
- FCKeditor漏洞利用
FCKeditor漏洞利用 查看编辑器版本 FCKeditor/_whatsnew.html fckeditor/editor/dialog/fck_about.html —————————————— ...
- xss实例-输出在<script></script>之间的情况
1. 我们找到这么一个点,也是输入和输出都未过滤的一个点.相比教程第一例,其特殊之处在于,是输出在了 <script>[输出]</script>之间. http://activ ...
- 新浪微博客户端(20)-集成MJRefresh
HomeViewController.m /** 集成下拉刷新控件 */ - (void)setupPullToRefreshView { __unsafe_unretained UITableVie ...
- mysql 的设置
网上的一些文章都已经比较老了,现在版本高了之后,其实配置是很省力的(不考虑什么负载的话) 分享全过程,出了文中提到的安装epel rpmfushion 源指令不同外,其他的过程也适用与Centos 5 ...