-
Notifications
You must be signed in to change notification settings - Fork 1
/
1328.cpp
37 lines (33 loc) · 1.03 KB
/
1328.cpp
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
class Solution {
public:
string breakPalindrome(string palindrome) {
if(palindrome.size()==1){
return "";
}
if(palindrome.length()%2==0){
int i;
for( i=0;i<palindrome.length();i++){
if(palindrome[i]!='a'){
palindrome[i]='a';
return palindrome;
}
}
if(i==palindrome.length()){
palindrome[palindrome.length()-1]='b';
return palindrome;
}
}
else{
int i;
for( i=0;i<palindrome.length();i++){
if(i!=(palindrome.length()/2) && palindrome[i]!='a'){
palindrome[i]='a';
return palindrome;
}
}
palindrome[palindrome.length()-1]='b';
return palindrome;
}
return palindrome;
}
};