LintCode Two Strings Are Anagrams
1. 把string变为char数组
2. 排序Arrays.sort()
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 == null || t == null) return false;
if(s.length() != t.length()) return false; char[] arrs = s.toCharArray();
char[] arrt = t.toCharArray();
Arrays.sort(arrs);
Arrays.sort(arrt); boolean flag = true;
for(int i = 0; i < arrs.length; i++){
if(arrs[i] != arrt[i]){
flag = false; }
}
return flag;// write your code here
}
};
LintCode Two Strings Are Anagrams的更多相关文章
- Two Strings Are Anagrams
Write a method anagram(s,t) to decide if two strings are anagrams or not. 判断两个字符串里的字符是否相同,也就是是否能够通过改 ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- [LeetCode] Anagrams 错位词
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- LeetCode-Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- 【Leetcode】【Medium】Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- [LeetCode]题解(python):049-Groups Anagrams
题目来源 https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For ...
- 49. Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- LeetCode49 Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
随机推荐
- Myeclipse安装SVN插件(转)
方法一:在线安装 1.打开HELP->MyEclipse Configuration Center.切换到SoftWare标签页. 2.点击Add Site 打开对话框,在对话框Name输入Sv ...
- Promise
function getURL(URL) { return new Promise(function (resolve, reject) { var req = new XMLHttpRequest( ...
- Swift函数
函数 函数 介绍 // func // 在Swift中,一个个的方法就是函数 // 1.定义函数的关键字是func // 在定义函数的时候,不管有没有参数都加括号,参数写在括号中 // 在定义函数时, ...
- 搭建Android开发环境。
1. 从 http://developer.android.com/intl/zh-cn/sdk/index.html 下载ADK 2. 点击SDK.Manager.exe, 遇到闪退的问题,一开始还 ...
- 软件测试第四周--关于int.parse()的类型转换问题
先来归纳一下我们用过的所有类型转换方法: 1. 隐式类型转换,即使用(int) 直接进行强制类型转换.这种方法的优点是简单粗暴,直接指定转换类型,没有任何保护措施,所以也很容易抛出异常导致程序崩溃.当 ...
- X3850M2安装CertOS 7 KVM 2--DMMP
1,在DS8000中调整vg为单台服务器.检查另一台服务器内已经没有磁盘信息. 2,在余下的服务器中安装DMMP. 参考:http://edwin-wang.com/2012/08/device-ma ...
- 移动混合开发之android文件管理-->flexbox,webFont。
增加操作栏,使用felxbox居中,felx相关参考网址:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html 使用webFont添加图标, ...
- Android 数据库管理— — —创建数据库
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...
- TypeScript 中的 "=>" 真的很好用!!!
class funs { public $scope: IBarPadScope; constructor($scope: IBarPadScope) { this.$scope = $scope; ...
- 【Python】使用正则表达式实现计算器练习
已知有以下这样一个不太友好的公式: 1 - 2 * ( (60-30 +(-9-2-5-2*3-5/3-40*4/2-3/5+6*3) * (-9-2-5-2*5/3 + 7 /3*99/4*2998 ...