标签:
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.
思路:
将两个字符串转为char数组,排序后查看二者是否相等。
解法:
1 import java.util.Arrays; 2 3 public class Solution 4 { 5 public boolean isAnagram(String s, String t) 6 { 7 char[] charS = s.toCharArray(); 8 char[] charT = t.toCharArray(); 9 10 Arrays.sort(charS); 11 Arrays.sort(charT); 12 13 if(Arrays.equals(charS, charT)) 14 return true; 15 else 16 return false; 17 } 18 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5732336.html