class Solution {
public:
int uniqueMorseRepresentations(vector<string>& words) {
string codes[26] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
std::set<string> uniqueTrans;
for (int i = 0; i < words.size(); i++) {
string transformed;
for (int j = 0; j < words[i].size(); j++) {
transformed += codes[words[i][j]-'a'];
}
uniqueTrans.insert(transformed);
}
return uniqueTrans.size();
}
};
LeetCode 804 Unique Morse Code Words 唯一摩尔斯密码词
最新推荐文章于 2024-04-18 22:52:58 发布