-
-
Notifications
You must be signed in to change notification settings - Fork 195
[YeomChaeeun] Week 14 #1091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[YeomChaeeun] Week 14 #1091
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Queue 를 사용한 BFS로 문제를 잘 풀어주셨네요!
공간복잡도를 최적화 하기 위해 DFS 문제 풀이도 도전해보시면 재미있을것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
14주차 문제 풀이 고생하셨습니다!
어느덧 15주차 마지막주가 다가왔네요.
아무쪼록 지난 15주 동안 릿코드 스터디가 많은 도움이 되셨으면 좋겠습니다.
다음주에 뵙겠습니다!
function countBits(n: number): number[] { | ||
const result: number[] = []; | ||
|
||
// 비트 연산을 이용해 1의 개수를 세는 함수 - O(log n) | ||
function countOnes(num: number): number { | ||
let count = 0; | ||
while (num > 0) { | ||
num &= (num - 1); // 가장 오른쪽의 1 비트를 제거 | ||
count++; | ||
} | ||
return count; | ||
} | ||
|
||
for (let i = 0; i <= n; i++) { | ||
result.push(countOnes(i)); | ||
} | ||
|
||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YeomChaeeun 님 안녕하세요!
코드의 가독성이 좋고, 비트 연산 방식이 제가 사용한 방법보다 더 효율적이어서 도움이 되었습니다. 여유가 된다면, DP로도 풀어보는 것을 추천드립니다! 이번 주도 고생하셨습니다 👍
답안 제출 문제
Week 13
Week 14
체크 리스트
In Review
로 설정해주세요.