deno.land / x / masx200_leetcode_test@10.6.5 / shortest-distance-to-a-character / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
export default function shortestToChar(s: string, c: string): number[] { const cache = [ ...Array.from(s) .map((v) => v === c) .entries(), ] .filter(([_i, b]) => b) .map(([i]) => i); return Array.from(s).map((_v, i) => { return Math.min(...cache.map((p) => Math.abs(p - i))); });}
masx200_leetcode_test

Version Info

Tagged at
a year ago