Given A string S1, we may represent it as a binary tree by partitioning it to the Non-empty substrings Recursivel Y.
Below is one possible representation of S1 = "great" :
Great / gr eat/\ / g r E at / a t
To scramble the string, we are choose any non-leaf node and swap it to the children.
For example, if we choose the node "gr" and swaps its-children, it produces a scrambled string "rgeat" .
Rgeat / RG eat/\ / r G e at / a t
We say is "rgeat" a scrambled string of "great" .
Similarly, if we continue to swap the children of nodes "eat" "at" and, it produces a scrambled string "rgtae" .
Rgtae / RG tae/\ / r G ta e / t a
We say is "rgtae" a scrambled string of "great" .
Given strings S1 and S2 of the same length, determine if S2 is a scrambled string of S1.
Mistake point: When doing the problem, must first think clearly the logic to do again
2, must pay attention to the cross-border problem, it is best to use a few test samples to run one step at a
Answer Address: http://www.cnblogs.com/easonliu/p/3696135.html
Leetcode Scramble String