public class Solution {
public boolean isScramble(String s1, String s2) {
if(s1.length()!=s2.length())return false;
int x1=0,x2=0;
for(char c:s1.toCharArray()){
x1=x1^(int)c;
}
for(char c:s2.toCharArray()){
x2=x2^(int)c;
}
if(x1!=x2)return false;
if(s1.length()==1)return s1.equals(s2);
for(int i=1;i<s1.length();i++){
if((isScramble(s1.substring(0,i),s2.substring(0,i))&&
isScramble(s1.substring(i),s2.substring(i)))||
(isScramble(s1.substring(0,i),s2.substring(s2.length()-i))&&
isScramble(s1.substring(i),s2.substring(0,s2.length()-i))))
return true;
}
return false;
}
}