题目链接:https://leetcode.com/problems/unique-morse-code-words/description/
题目解析:字符串去重用set即可。
代码如下:0ms Accepted
class Solution {
public:
int uniqueMorseRepresentations(vector<string>& words) {
string morse[26] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
set <string> S;
for (auto word : words)
{
string s;
for (auto c : word)
s += morse[c - 'a'];
S.insert(s);
}
return S.size();
}
};