deno.land / x / masx200_leetcode_test@10.6.5 / smallest-string-with-a-given-numeric-value / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export default function getSmallestString(n: number, k: number): string { if (n * 26 === k) return "z".repeat(n); let s = "", num = 0; for (let i = 0; i < n; i++) { const diff = (n - i - 1) * 26 - (k - num); if (diff >= 0) { s += "a"; num++; } else { const code = Math.abs(diff); num += code; s += String.fromCharCode(code + 96); break; } } return s.padEnd(n, "z");}
masx200_leetcode_test
leetcode题解和一些测试工具
DocumentationDocumentation
GitHub Repositorymasx200/leetcode-test
GitHub Stars
4

Version Info

Tagged at
4 months ago