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)