deno.land / x / masx200_leetcode_test@10.6.5 / first-unique-character-in-a-string / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export default function firstUniqChar(s: string): number { const cnts: Record<string, number> = {}; for (const w of (s)) { const arr = (cnts[w] ?? 0);
cnts[w] = arr + 1; }
for (const [i, w] of Array.prototype.entries.call(s)) { if (cnts[w] === 1) { return i; } } return -1;}
masx200_leetcode_test

Version Info

Tagged at
a year ago