LintCode-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.
For A = "ABCD", B = "ABC", return true.
For A = "ABCD" B = "AABC", return false.
Solution:
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) {
int[] record = new int[256];
Arrays.fill(record,0);
for (int i=0;i<A.length();i++){
int ind = (int) A.charAt(i);
record[ind]++;
}
for (int i=0;i<B.length();i++){
int ind = (int) B.charAt(i);
if (record[ind]==0) return false;
else record[ind]--;
}
return true;
}
}
LintCode-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" ...
- Compare Strings
Compare two strings A and B, determine whether A contains all of the characters in B. The characters ...
- LintCode Two Strings Are Anagrams
1. 把string变为char数组 2. 排序Arrays.sort() public class Solution { /** * @param s: The first string * @pa ...
- 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 ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
随机推荐
- MarkDown认识与入门
Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown 的语法十分简单.常用的标记符号也不 ...
- for in
1 for in 循环如果遍历的是数组 那么 i 就是数组的索引值 var x; var person=[456,"qwe",890]; for (x in person) ...
- java之旅——JDK版本下载
作为一名IT工作者,技术学无止境,最近开始学习java. 学习java就需要安装jdk,直接到官网上下载,总是找不到很好的版本,在资源中找到一个下载jdk的链接,想下载哪个版本都有. http://w ...
- Win7 安装.net framework 4.0 失败
Win7 安装.net framework 4.0 失败,错误HRESULT 0xc8000222解决办法 单独安装.net framework 4.0,结果还是失败,出现HRESULT 0xc800 ...
- chromium浏览器开发系列第二篇:如何编译最新chromium源码
说一下为什么这么晚才发第二篇,上周和这周department的工作太多了,晚上都是十点半从公司出发,回家以后实在没有多余的精力去摸键盘了.所以请大家包涵! 上期回顾: chromium源码下载: 1. ...
- 64位系统下注册32位dll文件
64位系统下注册32位dll文件 在64位系统里注册32位软件所需的一些dll会提示不兼容,大概因为32 位进程不能加载64位Dll,64位进程也不可以加载32的导致. 若要支持的32 位和64 位C ...
- HTML+CSS学习笔记 (14) - 单位和值
标签:HTML+CSS 颜色值 在网页中的颜色设置是非常重要,有字体颜色(color).背景颜色(background-color).边框颜色(border)等,设置颜色的方法也有很多种: 1.英文命 ...
- 银联接口测试——详细(JAVA)
准备材料 1.注册账号 https://open.unionpay.com/ajweb/register?locale=zh_CN 2.▼登录账号 -->帮助中心--> 下载,选择网关支付 ...
- 【OSG细节实现】节点围绕位于axisPos平行于axis的轴进行旋转
//绕着与axis平行的任意轴旋转 void rotate(const std::string& name, float angle, osg::Vec3 axisPos, osg::Vec3 ...
- 《RPM源码包的制作》RHEL6
一下rpm包的创建不含编译部分: 首先写个脚本,这个脚本是你想干的事..useradd.sh是我写的脚本,批量添加20个用户.我们创建一个目录,将脚本放进去: 将此目录压缩: 我们将校验的key导出: ...