Leetcode 804 唯一摩尔斯密码词
没什么难度,水题。如果不是每日一题不建议刷。
代码语言:javascript复制#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;
class Solution {
public:
int uniqueMorseRepresentations(vector<string>& words) {
vector<string> password{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
map<string,bool> exist;
for(int i=0;i<words.size();i ){
string& word = words[i];
string origin;
for(int j=0;j<word.length();j ){
origin = origin password[word[j]-'a'];
}
exist[origin]=true;
}
return exist.size();
}
};
int main(void){
Solution s;
vector<string> words;
words.emplace_back("gin");
words.emplace_back("zen");
words.emplace_back("gig");
words.emplace_back("msg");
cout<<s.uniqueMorseRepresentations(words)<<endl;
return 0;
}