Minimum Length of String After Deleting Similar Ends LeetCode solution in C++

1
class Solution {
2
public:
3
int minimumLength(string s) {
4
int i = 0, j = s.length() - 1;
5
while (i < j) {
6
if (s[i] != s[j]) {
7
break;
8
} else {
9
char x = s[i];
10
while (s[i] == x) {
11
i++;
12
}
13
if (i > j) {
14
return 0;
15
}
16
while (s[j] == x) {
17
j--;
18
}
19
if (j < i) {
20
return 0;
21
}
22
}
23
}
24

25
return j - i + 1;
26
}
27
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0