Skip to content

Commit a606b56

Browse files
committed
Runtime: 0 ms (Top 100.0%) | Memory: 6.60 MB (Top 43.9%)
1 parent e1fc698 commit a606b56

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
//the major obersavation or we can also verify by giving your own test it always returns 1 or 2
2-
//if the whole string is palindrom then return 1 if not then return 2.
1+
// Runtime: 0 ms (Top 100.0%) | Memory: 6.60 MB (Top 43.9%)
2+
33
class Solution {
4-
static bool isPal(string s){
5-
string p = s;
6-
reverse(p.begin() , p.end());
7-
return s==p;
8-
}
94
public:
10-
int removePalindromeSub(string s) {
11-
12-
if(isPal(s)){
13-
return 1;
14-
}
15-
16-
return 2;
5+
int removePalindromeSub(string S) {
6+
if (S == "") return 0;
7+
for (int i = 0, j = S.size() - 1; i < j; i++, j--)
8+
if (S[i] != S[j]) return 2;
9+
return 1;
1710
}
1811
};

0 commit comments

Comments
 (0)