| 13 | |
| 14 | |
| 15 | class Solution { |
| 16 | private: |
| 17 | char *alphabet_morse[26] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}; |
| 18 | public: |
| 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 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected