MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/UniqueMorseCode/solution.cpp:15–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14
15class Solution {
16private:
17 char *alphabet_morse[26] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
18public:
19 int uniqueMorseRepresentations(vector<string>& words) {
20 vector<string> morse_answers;
21 vector<string> answer;
22 int i = 0;
23 for(int i=0; i<words.size(); i++){
24 answer = {};
25 for(int j=0; j<words[i].size(); j++)
26 answer.push_back(alphabet_morse[int(words[i][j]) - 97]);
27
28 char morse[50] = "\0";
29 int k = 0;
30 for(int i=0; i<answer.size() ;i++)
31 for(int j=0; answer[i][j]!='\0'; j++){
32 morse[k] = answer[i][j];
33 k++;
34 }
35 morse[k] = '\0';
36 morse_answers.push_back(morse);
37 }
38 std::sort(morse_answers.begin(), morse_answers.end());
39 int uniqueCount = std::unique(morse_answers.begin(), morse_answers.end()) - morse_answers.begin();
40 return uniqueCount;
41 }
42};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected