文章目录
题意
思路
计算
代码
C++
class Solution {
public:
vector<string> getFolderNames(vector<string>& names) {
set<string> s;
vector<string> ans;
map<string, int> m;
for (auto &it:names) {
if (s.count(it) == 0) {
m[it]++;
s.insert(it);
ans.push_back(it);
} else {
int i = m.count(it) ? m[it] : 1;
while (s.count(it + string("(") + to_string(i) + string(")")))
i++;
const string tmp = it + string("(") + to_string(i) + string(")");
m[it] = i + 1;
s.insert(tmp);
ans.push_back(tmp);
}
}
return ans;
}
};```