@@ -0,0 +1,1322 @@
+import java.util.Arrays;%0A%0Apublic class Solution%7B%0A%0A    /**%0A     * Solution 1: Sort the strings, see if they are equal%0A     */%0A  public static boolean checkPermutation(String s, String t)%7B%0A    if (s.length() != t.length())%7B%0A      return false;%0A    %7D%0A    return sort(s).equals(sort(t));%0A  %7D%0A  public static String sort(String s)%7B%0A    char%5B%5D content = s.toCharArray();%0A    // Implementation note: The sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations.%0A    Arrays.sort(content);%0A    return new String(content);%0A  %7D%0A%0A  /**%0A   * Solution 2: Check if the two strings have identical character counts%0A   */%0A  public static boolean checkPermutationsByCharCount(String s, String t)%7B%0A    if (s.length() != t.length())%7B%0A      return false;%0A    %7D%0A    int%5B%5D letters = new int%5B256%5D; // Assuming ASCII extended%0A    char%5B%5D s_array = s.toCharArray();%0A    for(char c: s_array)%7B%0A      letters%5Bc%5D++;%0A    %7D%0A    for(int i = 0; i %3C t.length(); i++)%7B%0A      int c = (int) t.charAt(i);%0A      letters%5Bc%5D--;%0A      if(letters%5Bc%5D %3C 0)%7B%0A        return false;%0A      %7D%0A    %7D%0A    return true;%0A%0A  %7D%0A%7D%0A

Check Permutations