一:题目
二:上码
class Solution {
public:/**1.所谓字母异位词就是相同的字母组成的字符串(这个字符串可以相同)2.首先判断两个字符串中的字母是否相同用map进行计数,然后在另一个字符串中查找某个字符进行--;3.如果最终的map中所有的value为0那么就删除**/bool isJudge(string str1,string str2) {map<char,int>m;for (int i = 0; i < str1.size(); i++) {m[str1[i]]++;}for (int i = 0; i < str2.size(); i++) { auto temp = m.find(str2[i]);if (temp != m.end()) m[str2[i]]--;if (temp == m.end()) return false;//从str2中查到了str1中不存在的字符}for (auto mt = m.begin(); mt != m.end(); mt++) {if (mt->second != 0) return false;}return true;}vector<string> removeAnagrams(vector<string>& words) {vector<string>ans;int i = 0;for (int j = 1; j < words.size(); j++) {if (isJudge(words[i],words[j])) {words[j] = "-1"; } else {i = j;}}for (int j = 0; j < words.size(); j++) {if (words[j] != "-1") ans.push_back(words[j]);}return ans;}
};