Facebook
From Hussain Imtiaz, 4 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 266
  1. class Solution {
  2. public:
  3.     int uniqueMorseRepresentations(vector<string>& words) {
  4.        unordered_set<string> m;
  5.         string values[26] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
  6.         for(string s:words){
  7.             string a = "";
  8.             for(int i = 0;i<s.length();i++){
  9.                 a += values[s[i] - 97];
  10.             }
  11.             m.insert(a);
  12.         }
  13.         return m.size();
  14.     }
  15. };