map标记即可
注意对于某个文件名生成的结果文件名也需要标记一下
class Solution { public: vector<string> ret; map<string, int> mmap; vector<string> getFolderNames(vector<string>& names) { int n = names.size(); for(int i = 0; i < n; i++) { if(mmap[names[i]]) { string tmp = names[i]; while(mmap[tmp]) { string str; stringstream ss; ss << mmap[names[i]]; ss >> str; tmp = names[i] + "(" + str + ")"; mmap[names[i]]++; } mmap[tmp]++; ret.push_back(tmp); } else { ret.push_back(names[i]); mmap[names[i]]++; } } return ret; } };