forked from larissalages/code_problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1576.cpp
More file actions
27 lines (27 loc) · 784 Bytes
/
1576.cpp
File metadata and controls
27 lines (27 loc) · 784 Bytes
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
class Solution {
public:
string modifyString(string s) {
string alphabets="abcdefghijklmnopqrstuvwxyz";
char chr;
for(int i=0;i<s.length();i++){
if(s[i]=='?'){
chr=alphabets[rand()%26];
if(i>0 && i<s.length()-1){
while(chr==s[i-1] || chr==s[i+1]){
chr=alphabets[rand()%26];
}
}else if(i>0){
while(chr==s[i-1]){
chr=alphabets[rand()%26];
}
}else{
while(chr==s[i+1]){
chr=alphabets[rand()%26];
}
}
s[i]=chr;
}
}
return s;
}
};