publicbooleanisScramble(String s1,String s2) {// if len is different, they won't be scrable of each otherif (s1.length() !=s2.length()) {returnfalse; }// if both are empty string, or they equal to each other, they are scrable stringif (s1.isEmpty() ||s1.equals(s2)) {returntrue; }// cut down the compare when 2 string doesn't have same amount of charsif (!isValid(s1, s2)) {returnfalse; }// now try to cut both strings at each of location between 1 to len - 1int len =s1.length();for (int i =1; i < len; i++) {String s11 =s1.substring(0, i);String s12 =s1.substring(i, len);String s21 =s2.substring(0, i);String s22 =s2.substring(i, len);String s23 =s2.substring(0, len - i);String s24 =s2.substring(len - i, len);if (isScramble(s11, s21)&&isScramble(s12, s22)) {returntrue; }if (isScramble(s11, s24)&&isScramble(s12, s23)) {returntrue; } }returnfalse;}privatebooleanisValid(String s1,String s2) {char[] c1 =s1.toCharArray();char[] c2 =s2.toCharArray();Arrays.sort(c1);Arrays.sort(c2);String sorted1 =newString(c1);String sorted2 =newString(c2);if (!sorted1.equals(sorted2)) {returnfalse; }returntrue;}