Valid Anagram【LeetCode】
来源:互联网 发布:安装java linux 编辑:程序博客网 时间:2024/06/05 14:17
题目:
Given two string 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.
Follow up:
What if the input contain unicode characters? How would you adapt your solution to such case?
思路分析:
判断连个字符串是不是相同字符,可以通过排序,判断排序之后的字符是否相等即可
代码:
public class Solution{ public boolean isAnagram(String s, String t{char[] oneArray = s.toCharArray();char[] twoArray = s.toCharArray();Arrays.sort(oneArray);Arrays.sort(twoArray);int oneLength = oneArray.length;int twoLength = twoArray.length;if(oneLength!=twoLength){return false;}else{for(int i=0;i<oneLength;i++){if(oneArray[i]!=twoArray[i]){return false;}elsereturn true;}}return false;}}参考链接点击打开链接
阅读全文
0 0
- Leetcode #242 Valid Anagram
- leetcode-242-Valid Anagram
- Leetcode: Valid Anagram
- 【leetCode】Valid Anagram
- [leetcode] 242.Valid Anagram
- leetcode 242: Valid Anagram
- 【leetcode】Valid Anagram
- [leetcode] Valid Anagram
- LeetCode Valid Anagram
- 【LeetCode】242 Valid Anagram
- [LeetCode] Valid Anagram
- leetcode: Valid Anagram
- leetCode(53):Valid Anagram
- leetcode Valid Anagram 异位体
- [leetcode 242]Valid Anagram
- leetcode Valid Anagram
- leetCode #242 Valid Anagram
- LeetCode题解:Valid Anagram
- [PAT-乙级]1049.数列的片段和
- Unity FixedJoint
- File.separator
- Hadoop中Partition解析
- 排序算法之简单选择排序
- Valid Anagram【LeetCode】
- fread与fwrite读取数字或数组
- 服务器网络故障处理——常见链路异常场景和测试报告
- 《PCL点云库学习&VS2010(X64)》Part 39 批处理命令设置PCL的环境变量
- ora-12638:身份证明检索失败
- IDEA上传代码到码云/git
- 爬楼梯-斐波那契
- [2016陕西省赛B] Rui and her functions
- display取值的用法