Skip to content

[0] 자동차 경주 게임 구현#3

Open
deok-beom wants to merge 6 commits intoCODE-CLEANERS:mainfrom
deok-beom:level_2_racing
Open

[0] 자동차 경주 게임 구현#3
deok-beom wants to merge 6 commits intoCODE-CLEANERS:mainfrom
deok-beom:level_2_racing

Conversation

@deok-beom
Copy link

No description provided.

Copy link
Collaborator

@ca1af ca1af left a comment

Choose a reason for hiding this comment

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

멋쥡니당! 머지솔트 잘보았읍니다 👍

Comment on lines +32 to +73
private void sort(Car[] cars, int left, int right) {
if (left >= right) {
return;
}

int middle = (left + right) / 2;

sort(cars, left, middle);
sort(cars, middle + 1, right);

merge(cars, left, middle, right);
}

private void merge(Car[] cars, int left, int middle, int right) {
Car[] leftArray = Arrays.copyOfRange(cars, left, middle + 1);
Car[] rightArray = Arrays.copyOfRange(cars, middle + 1, right + 1);

int i = 0, j = 0;
int cursor = left;
while (i < leftArray.length && j < rightArray.length) {
if (leftArray[i].getLocation() >= rightArray[j].getLocation()) {
cars[cursor] = leftArray[i];
i++;
} else {
cars[cursor] = rightArray[j];
j++;
}
cursor++;
}

while (i < leftArray.length) {
cars[cursor] = leftArray[i];
i++;
cursor++;
}

while (j < rightArray.length) {
cars[cursor] = rightArray[j];
j++;
cursor++;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

머지솔트 무엇...

}

public String getWinners() {
Car[] sortedCars = cars.sort();
Copy link
Collaborator

Choose a reason for hiding this comment

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

솔트해서 찾는다는 게 엄청 효율적인 접근 같아요! 시간복잡도를 낮출 수 있다는 점 멋집니당

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.

3 participants