diff options
Diffstat (limited to 'other/unique_morse_code_words.cpp')
-rw-r--r-- | other/unique_morse_code_words.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/other/unique_morse_code_words.cpp b/other/unique_morse_code_words.cpp new file mode 100644 index 0000000..2a6280e --- /dev/null +++ b/other/unique_morse_code_words.cpp @@ -0,0 +1,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); +} |