String. The explanation of the question stem is very complicated and confusing.
What does this question mean? The final result is to disrupt the order of letters in a string, so that you can determine whether a string can be disrupted by another string. How is this process disrupted? It is very simple. To give you a string, you must first find a point and cut it into two halves, you can swap the order of the two half to disrupt the source string, that is, the character in the two half is consistent with the relative order of all characters in the other half. For each half, you can repeat the above process.
So, how do you know where to interrupt? Poor effort. How do I know whether to perform the exchange operation after the interruption? In either case, recursion is possible. There is another question: the two strings must contain exactly the same characters. How can we determine this? The most violent way is to open two new strings, sort them, and judge whether the two new phases are not equal.
class Solution {public: bool isScramble(string s1, string s2) { if(s1 == "" && s2 == "") return true; if(s1.length() != s2.length()) return false; if(s1 == s2) return true; string s11(s1), s22(s2); sort(s11.begin(), s11.end()); sort(s22.begin(), s22.end()); if(s11 != s22) return false; for(int i=1;i<s1.length();i++){ if(isScramble(s1.substr(0, i), s2.substr(0, i))&&isScramble(s1.substr(i, s1.length()-i), s2.substr(i, s2.length()-i))) return true; else if(isScramble(s1.substr(0, i), s2.substr(s2.length()-i, i))&&isScramble(s1.substr(i, s1.length()-i), s2.substr(0, s2.length()-i))) return true; } return false; }};