解題思路:
(1)建立索引表,再將拼接成的字符串插入到集合中,最後返回集合的大小
class Solution {
public:
string alpha[26]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
/**
* @param words: the given list of words
* @return: the number of different transformations among all words we have
*/
int uniqueMorseRepresentations(vector<string> &words) {
set<string> s;
string str = "";
for(auto&& w:words) {
str = "";
for(auto&& k:w) {
str+=alpha[k-'a'];
}
s.insert(str);
}
return s.size();
}
};