Skip to content

Commit 2c944b8

Browse files
author
Pranjal
authored
Merge pull request #11 from pockemon/master
Scramble string added
2 parents e10a2bd + b29683a commit 2c944b8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)