c++(4ms 99%) set, easy (with comments)
Runtime: 4 ms, faster than 99.23% of C++ online submissions for Reorder Data in Log Files.\nMemory Usage: 10.7 MB, less than 87.97% of C++ online submissions fo
Runtime: 4 ms, faster than 99.23% of C++ online submissions for Reorder Data in Log Files.\nMemory Usage: 10.7 MB, less than 87.97% of C++ online submissions for Reorder Data in Log Files.\n**General idea**\n1 check if our log is numeric ?(function isNumeric)\n a) if is. retain this log in vector num ( we will have all numeric logs with their original order)\n b)if not. split our log on two parts and contain their in set<pair> in reversing order (we will have all letteric logs in set with sorting both the identifer and the log)\n  2 construct answer with num and set  (for log from set use reverse again)\n```\nclass Solution {\npublic:\n  bool isNumeric(string &s, int &i){\n    i = 0;\n    while(s[i++] != \' \');\n    return s[i] < \'a\';\n  }\n  \n  vector<string> reorderLogFiles(vector<string>& logs) {\n    set<pair<string,string>> tmp;\n    vector<string> answer, num;\n    int i;\n    \n    for(auto &w: logs)\n      if(isNumeric(w,i)) num.push_back(w);\n      else tmp.insert({w.substr(i,w.size()), w.substr(0,i)});\n    \n    for(auto &w : tmp) answer.push_back(w.second + w.first);\n    for(auto &w : num) answer.push_back(w);\n    \n    return answer;\n  }\n};\n```\n
['C', 'C++']