LeetCode——Valid Anagram
Description:
Given two strings s and t, write a function to determine if t is an anagram of s.
For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false.
Note: You may assume the string contains only lowercase alphabets.
public class Solution {
public static boolean isAnagram(String s, String t) {
if(s.equals(t)) {
return true;
}
char[] ss = s.toCharArray();
char[] tt = t.toCharArray();
Arrays.sort(ss);
Arrays.sort(tt);
return (new String(ss)).equals((new String(tt)));
}
}
LeetCode——Valid Anagram的更多相关文章
- [LeetCode] Valid Anagram 验证变位词
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...
- Leetcode Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...
- LeetCode() Valid Anagram 有问题!!!
为什么第一个通过,第二个不行呢? class Solution { public: bool isAnagram(string s, string t) { if(s.size() != t.size ...
- LeetCode Valid Anagram (简单题)
题意: 给出两个字符串s和t,判断串t是否为s打乱后的串. 思路: 如果返回的是true,则两个串的长度必定相等,所有字符出现的次数一样.那么可以统计26个字母的次数来解决,复杂度O(n).也可以排序 ...
- leetcode面试准备:Valid Anagram
leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- 【LeetCode】242. Valid Anagram (2 solutions)
Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For ...
- [leetcode]242. Valid Anagram验证变位词
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...
随机推荐
- Yii CDbCriteria常用用法
$criteria = new CDbCriteria;$criteria->compare('name',$this->name,true,'OR'); //like部分匹配//$cri ...
- CodeIgniter(3.1.4)框架使用静态文件(js,css)
调整目录结构: 可以在控制器中这样加载视图: * 加载url辅助类. views视图中可以这样引用静态文件: 则最终的静态文件url会生成这样:
- ARDUINO PWM
转至:http://www.sl088.com/voyage/2012/10/11506.slboat#.E5.8F.91.E7.8E.B0 http://www.engblaze.com/micro ...
- Windoows窗口程序一
编写窗口程序的步骤: .定义WinMain入口函数 .定义窗口处理函数(处理消息)WindowProc .注册窗口类RegisterClass .创建窗口(在内存中创建窗口)CreateWindow ...
- Linux make语法补充
"-"表示此条命令出错,make也会继续执行后续的命令.如:"-rm main.o" 内置变量$@表示生成目标 内置变量$^表示所有依赖 内置变量$<表示 ...
- 最小顶点覆盖(Minimum Vertex Cover)与最大独立集(Maximum Independent Set)
问题描述:就是在图中找最小的点集,使得覆盖所有边. 和独立集等价:独立集问题:在图中找最大的点集,使得点集内的所有点互不相连. 引理:顶点覆盖集和独立集互补. 上面这个引理使得这两个问题可以相互规约, ...
- ubuntu开启SSH服务远程登录
http://blog.csdn.net/jackghq/article/details/54974141 ubuntu开启SSH服务远程登录
- JDK中的序列化和反序列化
题外话:诸事缠身,不知不觉距离上一篇就将近一个月了,读书不易,学习不易,唯有坚持. 写来写去始终不满意,索性贴一个比较好的文章吧! 参考: [Java基础]序列化与反序列化深入分析
- Java 关于finally、static
论坛上看到的两道题目,如下: //为啥运行结果是1 0 不是 0 0呢 谁能解释下啊 public class FinallyDemo { static int value = 0; static i ...
- 深入解析AsyncTask
REFRENCES:http://blog.csdn.net/hitlion2008/article/details/7983449 AsyncTask的介绍及基本使用方法 关于AsyncTask的介 ...