⭐️ 题目描述
🌟 leetcode链接:将句子排序
代码:
class Solution {
public:string sortSentence(string s) {vector<string> record;record.resize(9);string curString;for (auto val : s) {if (isdigit(val)) {record[ val - '0' - 1 ] = curString;curString.clear();} else if (isalpha(val)) {curString.push_back(val);}}string ans = record[0];for (int i = 1; i < 9; i++) {if (!record[i].empty()) {ans += " " + record[i];}}return ans;}
};