Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions counting-bits/reeseo3o.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Bit Manipulation
  • 설명: 이 코드는 이전 결과를 활용하여 현재 값을 계산하는 동적 프로그래밍과, 비트 연산을 이용한 비트 조작 패턴을 사용합니다. 이를 통해 효율적으로 1비트 수를 계산합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 배열을 한 번 채우는 반복문이 있으며, 각 i에 대해 이전 값과 비트 연산을 이용해 계산하므로 시간 복잡도는 선형입니다. 배열 크기만큼 공간을 사용합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Time Complexity: O(n)
// Space Complexity: O(n)

const countBits = (n) => {
const ans = new Array(n + 1).fill(0);

for (let i = 1; i <= n; i++) {
ans[i] = ans[i >> 1] + (i & 1);
}

return ans;
};
Loading