problem
solution:
class Solution { public: vector<string> reorderLogFiles(vector<string>& logs) { vector<string> letterlogs, digitlogs; for(auto log:logs) { int i=log.find(' '); if(isdigit(log[i+1])) digitlogs.push_back(log); else letterlogs.push_back(log); } sort(letterlogs.begin(), letterlogs.end(), [](string a, string b) { int i = a.find(' '); int j = b.find(' '); if(a.substr(i+1) == b.substr(j+1)) return a.substr(0, i-1) < b.substr(0, j-1);//err.... return a.substr(i+1) < b.substr(j+1); });//err... letterlogs.insert(letterlogs.end(), digitlogs.begin(), digitlogs.end()); return letterlogs; } };
参考
1. Leetcode_easy_937. Reorder Log Files;
2. discuss1_conpare;
3. discuss2_sort;
完