@@ -0,0 +1,1227 @@
+package problems;%0A%0Apublic class ScrambleString %7B%0A    public boolean isScramble(String s1, String s2) %7B%0A        if (s1.length() != s2.length())%0A            return false;%0A        if (s1.equals(s2))%0A            return true;%0A%0A        // check if two strings have same characters.%0A        int n = s1.length();%0A        int%5B%5D count = new int%5B256%5D;%0A        for (int i = 0; i %3C n; i++) %7B%0A            count%5Bs1.charAt(i)%5D++;%0A            count%5Bs2.charAt(i)%5D--;%0A        %7D%0A        for (int t : count) %7B%0A            if (t != 0)%0A                return false;%0A        %7D%0A%0A        // divide strings and check recursively.%0A        for (int i = 1; i %3C n; i++) %7B%0A            if (isScramble(s1.substring(0, i), s2.substring(0, i))%0A                    && isScramble(s1.substring(i), s2.substring(i)))%0A                return true;%0A            if (isScramble(s1.substring(0, i), s2.substring(n - i))%0A                    && isScramble(s1.substring(i), s2.substring(0, n - i)))%0A                return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        ScrambleString ss = new ScrambleString();%0A        %0A        String s1 = %22abc%22, s2 = %22bca%22;%0A        %0A        System.out.print(ss.isScramble(s1, s2));%0A    %7D%0A%7D%0A

Add Scramble String