class Solution {
public:
int uniqueMorseRepresentations(vector<string>& words) {
unordered_map<char,string> mp;
mp['a']=".-";
mp['b']="-...";
mp['c']="-.-.";
mp['d']="-..";
mp['e']=".";
mp['f']="..-.";
mp['g']="--.";
mp['h']="....";
mp['i']="..";
mp['j']=".---";
mp['k']="-.-";
mp['l']=".-..";
mp['m']="--";
mp['n']="-.";
mp['o']="---";
mp['p']=".--.";
mp['q']="--.-";
mp['r']=".-.";
mp['s']="...";
mp['t']="-";
mp['u']="..-";
mp['v']="...-";mp['w']=".--";mp['x']="-..-";mp['y']="-.--";mp['z']="--..";
set<string> s;
int n=words.size();
for(int i=0;i<n;i++)
{
int n1=words[i].size();
string s1="";
for(int j=0;j<n1;j++)
{
s1.append(mp[words[i][j]]);
}
s.insert(s1);
}
return s.size();
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter