Skip to content

Commit eabe2cf

Browse files
Create 0680-valid-palindrome-ii.cpp
1 parent 2d0e0cc commit eabe2cf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cpp/0680-valid-palindrome-ii.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
private:
3+
bool validPalindromeUtil(string s, int i, int j) {
4+
while(i < j)
5+
if(s[i] == s[j]) {
6+
i += 1;
7+
j -= 1;
8+
} else
9+
return false;
10+
return true;
11+
}
12+
public:
13+
bool validPalindrome(string s) {
14+
int i = 0, j = s.length() - 1;
15+
16+
while(i < j)
17+
if(s[i] == s[j]) {
18+
i += 1;
19+
j -= 1;
20+
} else
21+
return validPalindromeUtil(s, i + 1, j) || validPalindromeUtil(s, i, j - 1);
22+
return true;
23+
}
24+
};

0 commit comments

Comments
 (0)