deno.land / x / masx200_leetcode_test@10.6.5 / check-distances-between-same-letters / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export default function checkDistances(s: string, distance: number[]): boolean { const mp = new Map<number, number>();
for (const [i, c] of Array.prototype.entries.call(s)) { const key = c.charCodeAt(0) - "a".charCodeAt(0); const last = mp.get(key);
if ( mp.has(key) && typeof last !== "undefined" && i - last - 1 !== distance[key] ) { return false; } else { mp.set(key, i); } } return true;}
masx200_leetcode_test

Version Info

Tagged at
a year ago