Skip to content

Commit 2a12d0c

Browse files
authored
Merge pull request #7 from Chayandas07/Chayandas07-patch-7
Create 2 DEC 02 December Check if it is possible to convert one stri…
2 parents 4fbe524 + eb0873e commit 2a12d0c

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution
2+
{
3+
public:
4+
int isItPossible(string S, string T, int M, int N)
5+
{
6+
// code here
7+
if (count(S.begin(), S.end(), '#') != count(T.begin(), T.end(), '#'))
8+
return false;
9+
int i = 0, j = 0;
10+
while (i < M and j < N)
11+
{
12+
while (i < M and S[i] == '#')
13+
i++;
14+
15+
while (j < N and T[j] == '#')
16+
j++;
17+
18+
if ((i < M and j < N) and ((S[i] != T[j]) or (S[i] == 'A' and i < j) or (S[i] == 'B' and i > j)))
19+
return false;
20+
i++;
21+
j++;
22+
}
23+
return 1;
24+
}
25+
};

0 commit comments

Comments
 (0)