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 ...
随机推荐
- EF Code First 数据迁移命令
只需要开启程序管理控制台(Package Manager Console) 然后输入 Enable-Migrations -ContextTypeName youContextdb(你的数据库上下文 ...
- 第一个过滤器Filter
过滤器实现Filter接口javax.servlet.Filter package com.henau.example; import java.io.IOException; import java ...
- MySql运算符
算数运算符 加(+).减(-).乘(*).除(/).求余(%) 比较运算符 大于(>).小于(<).等于(=).大于等于(>=).小于等于(<=).不等于(!= 或者 < ...
- SlickOne -- 基于Dapper, Mvc和WebAPI 的快速开发框架
前言:在两年前,项目组推出了基于Dapper,Mvc和WebApi的快速开发框架,随着后续Slickflow产品的实践和应用,今再次对SlickOne项目做以回顾和总结.其目的是精简,持续改进,保持重 ...
- HTML_创建易用的Web表单
首先创建一个表单域集合fieldset fieldset元素允许Web开发者将主题相关的表单组合在一起 <fieldset></fieldset> 要说明的是本例子中每个表单都 ...
- Handler发送Message
用Handler更新UI package activity.cyq.handlermessage; import android.content.res.Resources; import andro ...
- CSS之隐藏元素
1.opacity=0,该元素隐藏起来了,但不会改变页面布局,并且,如果该元素已经绑定一些事件,如click事件,那么点击该区域,也能触发点击事件的2.visibility=hidden,该元素隐藏起 ...
- 解决$_REQUEST['name']Undefined问题
最近按照w3school一步一步学php,当学到$_REQUEST的时候,依旧按照w3cshool所提供的代码自己手敲了一遍,代码如下: <html> <body> <f ...
- Javascript获取URL地址变量参数值的方法
今天碰到在做一个动态页面的时候,需要用到 URL 的参数值来作判断,从而决定某一块内容在当前页面是否显示.例如exampe.html?parm1=xxx&parm2=xxx&parm3 ...
- jquery对象与js对象的相互转换
jQuery对象转成DOM对象: 两种转换方式将一个jQuery对象转换成DOM对象:[index]和.get(index); (1)jQuery对象是一个数据对象,可以通过[index]的方法,来得 ...