Skip to content

Conversation

@sooster910
Copy link

[5주차][정렬][Sue] 학습한 내용 정리입니다

주차 알고리즘 정리한 내용 링크
5주차 정렬 정렬 구현 및 문제 풀기 링크

Comment on lines +2 to +4
const solution = (arr) => {
return [...new Set(arr)].sort((a, b) => b - a);
};

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;

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) => {

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stages.length 는 항상 0이상이니 || 0은 없어도 되지 않을까요..?

Comment on lines +16 to +19
failure =
completedPlayersNum == 0
? 0
: (failure = count[i] / completedPlayersNum);
Copy link
Contributor

@bigsaigon333 bigsaigon333 Oct 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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];
Copy link
Contributor

@bigsaigon333 bigsaigon333 Oct 31, 2021

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]도 꽤 큰 비용일 수 있습니다 🐶

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요 배열의 길이가 크면 그만큼 다시 밀려서 비용이 커지니 push 낫겠네요. 혹시 더 괜찮은 방법 있으면 알려주세요 !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low-level 한 연산을 수행할 때는 그냥 push 하는게 공간복잡도, 시간복잡도 측면에서 제일 나은거 같아요 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants