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 ...
随机推荐
- asp.net MVC 如何隐藏 Response Header 版本号
根据借楼最少资源原则,有时候MVC需要隐藏自己的版本号,其实这里也是比较简单的,只需要在Global.ascx 的Application_Start()中添加一行代码既可 添加为 MVCHandle ...
- OpenShare文档中心
文档是企业重要的智力资产.在企业中,文档一般都以电子文档的形式存在,比如微软.doc格式,xls格式,ppt格式,pdf格式,纯文本.txt格式等:从内容上,可能是商务合同.会议记录.产品手册.客户资 ...
- SimpleDateFormat 相关用法
parse(String s)返回的是一个Date类型数据,format(Date d)返回的是一个String类型的数据 SimpleDateFormat sd = new SimpleDateFo ...
- C#传递参数
与函数交换数据的最好方式就是传递参数,在C#中有四种方法来控制参数如何传递给目标方法 C#中的参数修饰符 无修饰 如果一个参数没有用参数修饰符,则认为它将按值传递 out 输出参数由被调用的方法赋值. ...
- Part 12 Angularjs filter by multiple properties
In the example below, we are using multiple search textboxes. As you type in the "Search name&q ...
- 关于java中普通代码块、构造代码块与静态代码块
1.普通代码块 public static void main(String[] args) { /*普通代码块: *直接定义在在方法或语句中出现”{普通代码的执行语句}“的就称为普通代码块. *普通 ...
- php中magic_quotes_gpc对unserialize的影响
昨天朋友让我帮他解决下他网站的购物车程序的问题,程序用的是PHPCMS,换空间前是好的(刚换的空间),具体问题是提示成功加入购物车后跳转到购物车页面,购物车里为空. 我看了下代码,大致的原理就是将产品 ...
- List.Select按字符串选择属性
不知道大家有没有遇到这样的情况:List使用Lambda表达式的时候,想要选择项的某个属性列. 例如,选择编号ID: var idList=list.Select(o=>o.ID).ToList ...
- Hibernate中Entity实体类的写法
记录下一个Entity类的写法,方便以后查阅: package com.bupt.auth.entity; import java.util.Date; import javax.persistenc ...
- mstsc命令详解
1: 在xp sp2中用mstsc /console命令可以登录到远程桌面的控制台(和在电脑前以同一用户登录),xp升级到sp3后,不能这样用了.sp3中命令应该换成mstsc /admin. 2: ...