1
/**
2
* @param {string} s
3
* @param {character} c
4
* @return {number[]}
5
*/
6
var shortestToChar = function (s, c) {
7
let result = [];
8

9
for (let i = 0; i < s.length; i++) {
10
if (s.charAt(i) === c) result.push(0);
11
else {
12
const next = s.indexOf(c, i) === -1 ? Infinity : s.indexOf(c, i) - i;
13
const prev =
14
result.lastIndexOf(0) === -1 ? Infinity : i - result.lastIndexOf(0);
15
result.push(Math.min(next, prev));
16
}
17
}
18

19
return result;
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0