-
Notifications
You must be signed in to change notification settings - Fork 1
[WEEK10] 최준호 #44
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
Merged
[WEEK10] 최준호 #44
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| function solution(s) { | ||
| let zero = 0; | ||
| let count = 0; | ||
|
|
||
| while (s !== "1") { | ||
| const len = s.length; | ||
|
|
||
| s = s.replaceAll("0", ""); | ||
|
|
||
| const oneCount = s.length; | ||
|
|
||
| s = oneCount.toString(2); | ||
|
|
||
| zero += len - oneCount; | ||
| count++; | ||
|
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. 변수 가독성이 좋네요 😄 |
||
| } | ||
|
|
||
| return [count, zero]; | ||
| } | ||
|
|
||
| /* | ||
| 풀이 시간: 10분 | ||
|
|
||
| 시간 복잡도는 O(n log n)이다. | ||
| 공간 복잡도는 O(1)이다. | ||
|
|
||
| 문자열 s가 "1"이 될 때까지 반복하면서, 문자열 s에서 "0"을 제거하고, 남은 "1"의 개수를 구했다. | ||
| 그 다음에, "1"의 개수를 이진수 문자열로 변환했다. | ||
| 반복할 때마다 제거한 "0"의 개수를 zero에 더했고, 반복한 횟수를 count에 더했다. | ||
| 문자열 s가 "1"이 되면, [count, zero]를 반환했다. | ||
|
|
||
| 문제에서 요구사항을 그대로 구현하면 되는 문제였다. | ||
| 문자열 메서드를 오랜만에 사용해서 조금 헷갈렸다. | ||
| */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| function solution(A, B) { | ||
| var answer = 0; | ||
|
|
||
| A.sort((a, b) => a - b); | ||
| B.sort((a, b) => b - a); | ||
|
|
||
|
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. javascript sort함수로 역순을 이렇게 표현할 수 있군요 |
||
| for (let i = 0; i < A.length; i++) { | ||
| answer += A[i] * B[i]; | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| /* | ||
| 풀이 시간: 4분 | ||
|
|
||
| 시간 복잡도는 O(n log n)이다. | ||
| 공간 복잡도는 O(1)이다. | ||
|
|
||
| 배열 A는 오름차순으로 정렬하고, 배열 B는 내림차순으로 정렬했다. | ||
| 그 다음에, 배열 A와 배열 B의 요소들을 순회하면서, 각 요소들을 곱해서 answer에 더했다. | ||
|
|
||
| 눈치껏 최솟값과 최댓값을 곱하는 방식으로 풀이했다. | ||
| 근데 왜 그게 최솟값이 되는지는 잘 모르겠다. | ||
| */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
와 replaceAll은 생각지도 못했네요