-
Notifications
You must be signed in to change notification settings - Fork 1
[WEEK11] 이지현 #51
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
base: main
Are you sure you want to change the base?
[WEEK11] 이지현 #51
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| function solution(n) { | ||
| const countOne = (num) => num.toString(2).split("1").length - 1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 깔끔하네요! 👍 |
||
|
|
||
| const target = countOne(n); | ||
| let next = n + 1; | ||
|
|
||
| while (countOne(next) !== target) { | ||
| next++; | ||
| } | ||
|
|
||
| return next; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와 이해하기 쉽지 않군요ㅠ
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Charlie Puth - Left Right Left 가 생각나네요 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| function solution(n) { | ||
| let answer = 0; | ||
| let left = 1; | ||
| let right = 1; | ||
| let sum = 1; | ||
|
|
||
| while (left <= n) { | ||
| if (sum === n) { | ||
| answer++; | ||
| sum -= left; | ||
| left++; | ||
| } else if (sum < n) { | ||
| right++; | ||
| sum += right; | ||
| } else { | ||
| sum -= left; | ||
| left++; | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
-1은 없어도 되는 부분인 것 같아 보여요!