Anagram
- JAVA Code:
public static boolean isAnagram(String s, String t) { if (s.length() != t.length()) { return false; } int[] count = new int[26]; for (int i = 0; i < s.length(); i++) { count[s.charAt(i) - 'a']++; count[t.charAt(i) - 'a']--; } for (int i = 0; i < count.length; i++) { if (count[i] != 0) { return false; } } return true; }
Question: Given two strings s and t, determine whether t is an anagram of s.
Write a Java function with the following signature to solve the problem:
The function should take two strings s and t as input and return a boolean value indicating whether t is an anagram of s.
Note: An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Sample Input:
Input: s = "anagram", t = "nagaram"
Sample Output:
true