Mình co đang giải challenge sau của hackerrank: https://www.hackerrank.com/challenges/big-sorting/problem
Mình chỉ dùng bubble sort để sắp xếp vector các chuỗi cho trước:
// Complete the bigSorting function below.
vector<string> bigSorting(vector<string> unsorted) {
int n = unsorted.size();
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
if ((unsorted[i] > unsorted[j] && unsorted[i].size() == unsorted[j].size()) || (unsorted[i].size() > unsorted[j].size())) swap(unsorted[i], unsorted[j]);
}
}
return unsorted;
}
Với bubble sort thì chỉ vượt qua 7/9 testcases (2 testcase 6 và 7 bị Terminated due to timeout!). Mình có thử cài đặt Quicksort để sort thì gặp nhiều lỗi quá, ko biết mọi người có cách làm nào khá hơn không?
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?