-
-
Notifications
You must be signed in to change notification settings - Fork 247
[std-freejia] week 03 solutions #1805
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
Conversation
너무 늦게 올렸네요 늦어도 금요일까지는 in review 로 전환했어야 하는데.. |
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.
이번 한 주도 고생하셨습니다~! 🚀
} | ||
// 2자리 숫자로 해독 가능한 경우 | ||
if (num >= 10 && num <= 26) { | ||
dp[i] += dp[i-2]; |
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.
1차원 dp 리스트를 이용한 O(n) space DP로 풀이하셨네요! dp[i]
를 계산할 때 매 단계에서 dp[i - 1]
과 dp[i - 2]
만 확인하기 때문에, 이 값들을 두 개의 변수로 트래킹한다면 O(1) space DP로 최적화를 한 번 더 할 수 있을 것 같습니다~! 😀
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.
오! 변수로 트래킹 하는 방법도 있네요. 재밌을 것 같아요. 피드백 감사합니다 !!
int count = 0; | ||
while (n > 0) { | ||
if ((n & 1) == 1) count++; | ||
n >>= 1; |
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.
저도 해당 문제를 풀 때 수학적인 방식과 비트 조작 방식으로 접근했었는데요, 리트코드 솔루션을 보니 Brian Kernighan's Algorithm 이라는 풀이법도 있더라구요! n & (n - 1)
연산을 이용해 오른쪽에서부터 1인 비트를 하나씩 지워가며 개수를 세는 방식으로, n
에 포함된 1인 비트 개수만큼만 while 루프를 돌게 된다고 합니다.
참고 자료도 공유드려요~! ➡️ Link
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.
아. 끝까지 안가도 되는거군요. 링크까지 정말 감사합니다 !! 주말 잘보내세요!💛
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.
감사합니다 🙇🏻♀️ freejia 님도 좋은 주말 되세요~~!!
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!