-
Couldn't load subscription status.
- Fork 17
[5주차][정렬][Sue]학습내용정리 #57
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: sooster910
Are you sure you want to change the base?
Conversation
| const solution = (arr) => { | ||
| return [...new Set(arr)].sort((a, b) => b - a); | ||
| }; |
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.
진짜 간단하네요 👍
| tempArr.sort((a, b) => { | ||
| //국어점수 desc | ||
| if (b[1] > a[1]) return -1; | ||
| else if (b[1 < a[1]]) return 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.
else if (b[1 < a[1]]) return 1;
오타 찾았습니당
| .slice(1, n + 1) | ||
| .map((v) => v.split(" ").map((x) => Number(x) || x)); | ||
|
|
||
| tempArr.sort((a, b) => { |
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.
sort 오름차순, 내림차순이 반대로 되어있는 것 같아요
|
|
||
| const failureRates = []; | ||
| let failure; | ||
| let completedPlayersNum = stages.length || 0; |
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.
stages.length 는 항상 0이상이니 || 0은 없어도 되지 않을까요..?
| failure = | ||
| completedPlayersNum == 0 | ||
| ? 0 | ||
| : (failure = count[i] / completedPlayersNum); |
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.
| failure = | |
| completedPlayersNum == 0 | |
| ? 0 | |
| : (failure = count[i] / completedPlayersNum); | |
| const failure = | |
| completedPlayersNum === 0 | |
| ? 0 | |
| : count[i] / completedPlayersNum; |
요렇게 하는건 어떨까요?
| let res = []; | ||
| for (let i = 0; i < count.length; i++) { | ||
| for (let j = count[i]; j >= 0; j--) { | ||
| res = [...res, i]; |
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.
spread operator도 O(N) 이기 때문에, res가 충분히 커진다면 [...res, i]도 꽤 큰 비용일 수 있습니다 🐶
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.
그렇네요 배열의 길이가 크면 그만큼 다시 밀려서 비용이 커지니 push 낫겠네요. 혹시 더 괜찮은 방법 있으면 알려주세요 !
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.
low-level 한 연산을 수행할 때는 그냥 push 하는게 공간복잡도, 시간복잡도 측면에서 제일 나은거 같아요 😅
[5주차][정렬][Sue] 학습한 내용 정리입니다