File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ int Solution::isScramble (string A, string B)
2+ {
3+
4+ int length1 = A.length ();
5+ // int length2 = B.length();
6+
7+ if (length1 != B.length ())
8+ return false ;
9+ if (A == B)
10+ return true ;
11+
12+ bool scrambled[length1][length1][length1];
13+ for (int i=0 ; i < length1; ++i)
14+ {
15+ for (int j=0 ; j < length1; ++j)
16+ {
17+ scrambled[i][j][0 ] = (A[i] == B[j]);
18+ }
19+ }
20+
21+ for (int k=1 ; k < length1; ++k)
22+ {
23+ for (int i=0 ; i < length1 - k; ++i)
24+ {
25+ for (int j=0 ; j < length1 - k; ++j)
26+ {
27+ scrambled[i][j][k] = false ;
28+ for (int p=0 ; p < k; ++p)
29+ {
30+ if ((scrambled[i][j][p] && scrambled[i+p+1 ][j+p+1 ][k-p-1 ])
31+ || (scrambled[i][j+k-p][p] && scrambled[i+p+1 ][j][k-p-1 ])) {
32+ scrambled[i][j][k] = true ;
33+ break ;
34+ }
35+ }
36+ }
37+ }
38+ }
39+
40+ return scrambled[0 ][0 ][length1-1 ];
41+ }
You can’t perform that action at this time.
0 commit comments