From 1ae4b2c0686e0c05084036e6eff5b5156b02c20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tasha=28=EC=82=B4=EB=AF=B8=29?= <45252527+Lustellz@users.noreply.github.com> Date: Sat, 25 Oct 2025 20:34:20 +0900 Subject: [PATCH] solution on counting-bits --- counting-bits/Lustellz.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 counting-bits/Lustellz.ts diff --git a/counting-bits/Lustellz.ts b/counting-bits/Lustellz.ts new file mode 100644 index 000000000..37e486d41 --- /dev/null +++ b/counting-bits/Lustellz.ts @@ -0,0 +1,16 @@ +// Runtime: 6mx +// Memory: 61.10MB + +function countBits(n: number): number[] { + let answer: number[] = Array(n + 1).fill(0); + + for(let i = 1 ; i <= n ; i++){ + let tmp = i; + while (tmp > 0){ + answer[i] += tmp % 2 + tmp = Math.floor(tmp / 2) + } + } + + return answer; +};