-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings Valid Palindrome 2.cpp
More file actions
41 lines (39 loc) · 1.01 KB
/
Strings Valid Palindrome 2.cpp
File metadata and controls
41 lines (39 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Solution {
public:
bool checkpalin(string s){
int i=0;
int j=s.length()-1;
while(i<j){
if(s[i]==s[j]){
i++;
j--;
}else{
return false;
}
}
return true;
}
bool validPalindrome(string s) {
int i=0;
int j=s.length()-1;
while(i<j){
if(s[i]==s[j]){
i++;
j--;
}else{
string string1= s.substr(0,i) + s.substr(i+1,s.length());
string string2= s.substr(0,j) + s.substr(j+1,s.length());
cout<<string1<<" "<<string2<<endl;
bool flag1= checkpalin(string1);
bool flag2= checkpalin(string2);
if(flag1 || flag2){
return true;
}else{
return false;
}
}
}
return true;
}
};
//https://leetcode.com/problems/valid-palindrome-ii/