<commit_before>/*
Problem 242: Valid Anagram
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?
*/<commit_msg>Added solution to IsAnagram.java<commit_after>/*
Problem 242: Valid Anagram
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?
*/

import java.util.Arrays;

public class IsAnagram {
  public static boolean isAnagram(String s, String t) {
    int sLen = s.length(), tLen = t.length();
    if (sLen != tLen) return false;
    if (sLen == 0 && tLen == 0) return true;
    if (sLen == 0 || tLen == 0) return false; // this means that only one of them is 0

    char[] sArray = s.toCharArray();
    char[] tArray = t.toCharArray();

    Arrays.sort(sArray);
    Arrays.sort(tArray);

    for (int i = 0; i < sLen; i++) {
      if (sArray[i] != tArray[i])
        return false;
    }

    return true;
  }

  public static void main(String[] args) {
    System.out.println("isAnagram(\"\", \"\") = " + isAnagram("", ""));
    System.out.println("isAnagram(\"a\", \"\") = " + isAnagram("a", ""));
    System.out.println("isAnagram(\"\", \"b\") = " + isAnagram("", "b"));
    System.out.println("isAnagram(\"a\", \"b\") = " + isAnagram("a", "b"));
    System.out.println("isAnagram(\"anagram\", \"nagaram\") = " + isAnagram("anagram", "nagaram"));
    System.out.println("isAnagram(\"rat\", \"car\") = " + isAnagram("rat", "car"));
    System.out.println("isAnagram(\"hello\", \"hi\") = " + isAnagram("hello", "hi"));
    }
}
{'fraction_non_alphanumeric': 0.17333333333333334, 'fraction_numerical': 0.005925925925925926, 'mean_word_length': 3.4043478260869566, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1555030', 'n_tokens_mistral': 702, 'n_tokens_neox': 677, 'n_words': 229}