deno.land / x / masx200_leetcode_test@10.6.5 / string-compression / index.ts

نووسراو ببینە
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
36
37
38
export default function compress(chars: string[]): number { let writeindex = 0;
let count = 0; let current = ""; for (let readindex = 0; readindex < chars.length; readindex++) { const char = chars[readindex];
if (current === char) { count++; } else { flush();
current = char; count = 1; } } flush();
function flush() { if (current) { if (count > 1) { chars[writeindex] = current; writeindex++; const lenstring = count.toString(); for (const c of lenstring) { chars[writeindex] = c; writeindex++; } } else { chars[writeindex] = current; writeindex++; } } } return writeindex;}
masx200_leetcode_test

Version Info

Tagged at
a year ago