Java [Leetcode 242]Valid Anagram
题目描述:
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.
解题思路:
将字符串进行排序,然后逐个比较是否相同。
注意将数组转为String的时候需要使用String.valueOf()方法。不能用Array自带的toString()方法,详细原因见:http://www.cnblogs.com/ningvsban/p/3955483.html
代码如下:
public class Solution {
public boolean isAnagram(String s, String t) {
char[] s1 = s.toCharArray();
char[] t1 = t.toCharArray();
Arrays.sort(s1);
Arrays.sort(t1);
return String.valueOf(s1).equals(String.valueOf(t1));
}
}
Java [Leetcode 242]Valid Anagram的更多相关文章
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- LN : leetcode 242 Valid Anagram
lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...
- [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: ...
- LeetCode 242. 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] 242. Valid Anagram 验证变位词
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...
- LeetCode 242 Valid Anagram
Problem: Given two strings s and t, write a function to determine if t is an anagram of s. For examp ...
- (easy)LeetCode 242.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 242. Valid Anagram(有效的变位词)
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...
- Leetcode 242 Valid Anagram pytyhon
题目: Given two strings s and t, write a function to determine if t is an anagram of s. For example,s ...
随机推荐
- The content of element type "sqlMapConfig" is incomplete,
The content of element type "sqlMapConfig" is incomplete, it must match "(properties? ...
- win系统一键安装JDK和Tuxedo
@echo off title JDK和tuxedo环境变量设置 color 0a set /p inputTUX= [请输入你要设置的tuxedo的安装目录:] if /i "%input ...
- Tesseract初探
一.框架介绍 Tesseract 是一款图片识别工具,可以抓取图片中的文字,可以支持多种语言(默认是英语),需要下载开源文件可以在github上下载,如果知识应用不想太多深究直接在google cod ...
- encodeURIComponent()编码和decodeURIComponent()解码
html1: <!DOCTYPE HTML> <meta charset=utf-8> <meta http-equiv="X-UA-Compatible&qu ...
- Ubuntu的挂起和休眠
Ubuntu的挂起和休眠 之前一直没关注过这方面的信息,因为以前只是在台式机上面用Ubuntu,笔记本一直都是Windows.随着Windows越来越傻冒,最近决定将常用系统转为Ubuntu,才注意到 ...
- uva 11069
一开始打了个表 发现 a[i] = a[i-3]+a[i-2]; #include <iostream> #include <fstream> #include <cs ...
- Samza的ApplicationMaster
当Samza ApplicationMaster启动时,它做以下的事情: 通过STREAMING_CONFIG环境变量从YARN获取配置信息(configuration) 在随机端口上 启动一个JMX ...
- Hadoop将过时了?
http://www.kuqin.com/database/20120715/322528.html Hadoop这个单词如今铺天盖地,几乎成了大数据的代名词.仅仅数年时间,Hadoop从边缘技术迅速 ...
- setjump 和 longjump
goto语句可以用于同一个函数内异常处理,不幸的是,goto是本地的,它只能跳到所在函数内部的标号上.为了解决这个限制,C函数库提供了setjmp()和longjmp()函数,它们分别承担非局部标号和 ...
- ***SQL统计语句总结(运用场景:运营分析,财务分析等)
-- 统计三月的每天的数据量 ,) ,) ; --统计从5月19到6月29的数据量 , ) AS '日期', count(*) AS '医说数' FROM xm_feed a WHERE a.feed ...