-
Notifications
You must be signed in to change notification settings - Fork 0
/
1576.js
35 lines (34 loc) · 845 Bytes
/
1576.js
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
/**
* @param {string} s
* @return {string}
*/
var modifyString = function (s) {
const n = s.length
const arr = s.split('')
for (let i = 0; i < n; i++) {
if (arr[i] === '?') {
if (i === 0) {
arr[i] = arr[i + 1] === 'a' ? 'b' : 'a'
} else if (i === n - 1) {
arr[i] = arr[i - 1] === 'a' ? 'b' : 'a'
} else {
if (arr[i - 1] === 'a' || arr[i + 1] === 'a') {
if (arr[i - 1] === 'b' || arr[i + 1] === 'b') {
arr[i] = 'c'
} else {
arr[i] = 'b'
}
} else {
arr[i] = 'a'
}
}
}
}
return arr.join('')
}
/*
2022/01/05
80 95
字符串
大模拟
*/