本文主要是介绍leetcode:Valid Anagram 【Java】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、问题描述
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.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
无
三、算法代码
public class Solution {public boolean isAnagram(String s, String t) {char [] result1 = s.toCharArray();char [] result2 = t.toCharArray();Arrays.sort(result1);Arrays.sort(result2);s = String.valueOf(result1);t = String.valueOf(result2);return s.equalsIgnoreCase(t);}
}
这篇关于leetcode:Valid Anagram 【Java】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!