deno.land / x / masx200_leetcode_test@10.6.5 / rotated-digits / 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
export default function rotatedDigits(n: number): number { if (typeof cache[n] !== "undefined") return cache[n];
for (let i = 1; i <= 10000; i++) { cache[i] = cache[i - 1] + Number(isRotatedDigit(i)); }
return cache[n] ?? 0;}function isRotatedDigit(n: number) { const map: Record<string | number, number> = { 0: 0, 1: 1, 8: 8, 2: 5, 5: 2, 6: 9, 9: 6, }; const str = n.toString(); return ( ![3, 4, 7].some((d) => str.includes(d.toString())) && [...str].map((d) => map[d]).join("") !== str );}const cache: number[] = [0, 0, 1, 1, 1, 2, 3, 3, 3, 4, 4];
masx200_leetcode_test

Version Info

Tagged at
a year ago