Skip to content

Commit d61dd19

Browse files
authored
Merge pull request #1 from arafat-hasan/dev
adding many days
2 parents e2a6d58 + 86e21fb commit d61dd19

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

680.valid_palindrome_ii.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* FILE: 680.valid_palindrome_ii.cpp
3+
* @author: Arafat Hasan Jenin <opendoor.arafat[at]gmail[dot]com>
4+
* LINK: https://leetcode.com/problems/valid-palindrome-ii
5+
* DATE CREATED: 03-04-22 02:38:19 (+06)
6+
* LAST MODIFIED: 03-04-22 02:38:49 (+06)
7+
* VERDICT:
8+
*/
9+
10+
class Solution {
11+
public:
12+
bool validPalindrome(string s) {
13+
int i = 0;
14+
int j = s.size() - 1;
15+
16+
while (i <= j) {
17+
if (s[i] == s[j]) {
18+
i++;
19+
j--;
20+
} else
21+
return isPalindrome(s, i + 1, j) || isPalindrome(s, i, j - 1);
22+
}
23+
return true;
24+
}
25+
26+
bool isPalindrome(string s, int i, int j) {
27+
while (i <= j) {
28+
if (s[i] == s[j]) {
29+
i++;
30+
j--;
31+
} else
32+
return false;
33+
}
34+
return true;
35+
}
36+
};

0 commit comments

Comments
 (0)