程序员面试金典——11.2变位词排序
Solution1:
参考网址:https://www.nowcoder.com/profile/845063/codeBookDetail?submissionId=12676002
知识点:利用set中count函数的功能,查找是否存在某个值
class SortString {
public:
vector<string> sortStrings(vector<string> str, int n) {
// write code here
sort(str.begin(), str.end());
vector<string> res;
set<string> str_set;
for(int i = 0; i < str.size(); i++) {
string temp = str[i];
sort(temp.begin(), temp.end());
if(str_set.count(temp) == 0) {
str_set.insert(temp);
res.push_back(str[i]);
}
}
return res;
}
};