aboutsummaryrefslogtreecommitdiff
path: root/unique_morse_code_words.cpp
blob: 2a6280e748c10bf7b4a57707230ce0ae71dc945b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "leetcode.h"

class Solution {
public:
  int uniqueMorseRepresentations(vector<string> &words) {
    vector<string> codes = {
        ".-",   "-...", "-.-.", "-..",  ".",   "..-.", "--.",  "....", "..",
        ".---", "-.-",  ".-..", "--",   "-.",  "---",  ".--.", "--.-", ".-.",
        "...",  "-",    "..-",  "...-", ".--", "-..-", "-.--", "--.."};
    set<string> ans;
    for (auto word : words) {
      string curr = "";
      for (auto ch : word)
        curr += codes[ch - 97];
      ans.insert(curr);
    }
    return ans.size();
  }
};

int main() {
  Solution obj;
  vector<string> words = {"gin", "zen", "gig", "msg"};
  cout << obj.uniqueMorseRepresentations(words);
}