1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 int uniqueMorseRepresentations(vector<string>& words) 12 { 13 unordered_map<char,string> csmap={{'a',".-"},{'b',"-..."},{'c',"-.-."},{'d',"-.."},{'e',"."},{'f',"..-."},{'g',"--."},{'h',"...."},{'i',".."},{'j',".---"},{'k',"-.-"},{'l',".-.."},{'m',"--"},{'n',"-."},{'o',"---"},{'p',".--."},{'q',"--.-"},{'r',".-."},{'s',"..."},{'t',"-"},{'u',"..-"},{'v',"...-"},{'w',".--"},{'x',"-..-"},{'y',"-.--"},{'z',"--.."}}; 14 unordered_set<string> judge; 15 for(string &s:words) 16 { 17 string cur; 18 for(char &c:s) 19 { 20 cur=cur+csmap[c]; 21 } 22 judge.insert(cur); 23 } 24 int res=judge.size(); 25 return res; 26 } 27 };
一个map和一个set搞定,问题不大
浙公网安备 33010602011771号