LintCode
来源:互联网 发布:自动设计软件 编辑:程序博客网 时间:2024/05/10 07:50
- 两个字符串是变位词
- 比较字符串
两个字符串是变位词
import java.util.Arrays;public class Solution { /** * @param s: The first string * @param b: The second string * @return true or false */ public boolean anagram(String s, String t){ if (s.length() != t.length()){ return false; } char[] news = s.toCharArray(); char[] newt = t.toCharArray(); Arrays.sort(news); Arrays.sort(newt); for (int i = 0; i < news.length; i++){ if (news[i] != newt[i]){ return false; } } return true; }};
**注意:碰到类似题目应该询问要不要把空格算成一个char
比较字符串
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) { char[] array_b = B.toCharArray(); Arrays.sort(array_b); int count = 0; for (char b : array_b) { if(A.indexOf(b)!=-1){ String sb = Character.toString(b); A = A.replaceFirst(sb, ""); count++; } } if (count == B.length() || B=="") { return true; }else{ return false; } }}
**注意:碰到类似题目应该询问要不要把空格算成一个char
0 0
- LintCode
- lintcode--
- lintcode
- LintCode
- Lintcode
- Lintcode - Median
- Lintcode - MedianII
- Lintcode - Heapify
- LintCode-组合
- LintCode 子树
- LintCode-加油站
- lintcode-422
- lintcode-189
- lintcode-103
- lintcode-384
- lintcode-423
- lintcode-子树
- lintcode-366
- Java I/O操作
- Elasticsearch java API (17)Aggregations 聚合 函数
- 用dwz+springmvc出现这个问题Http status: 200 OK ajaxOptions: parsererror thrownError
- 关于Hibernate中创建ServiceRegistry对象时找不到ServiceRegistryBuilder对象的问题
- 忘了她,就像忘了一朵花
- LintCode
- java对象序列化和反序列化操作记录
- hdu_1950_Bridging signals(LIS)
- 理解php-cli环境
- CentOS命令行安装VMware tools
- Spark算子:RDD基本转换操作(5)–mapPartitions、mapPartitionsWithIndex
- Cornell 感受
- 简单的自定义圆形图片(不能与BitmapUtils一起使用)
- SSL与TLS的区别以及介绍