Title tag: String
First save the vowel letters into the HashSet.
Then split s into individual word, traversing each word:
When Word's first letter is not vowel, the first char is added to the last one;
Then add "Ma" and "a" to the last;
Add a new "a";
Add new word to result and remember to add a space.
Java Solution:
Runtime beats 62.66%
Completion Date: 10/12/2018
Keywords: String
Key points: Save vowel with HashSet
1 classSolution2 {3 Publicstring Togoatlatin (string S)4 {5String result = "";6Set<character> Vowelset =NewHashset<>();7String addOn = "a";8 9 for(CharC:New Char[]{' A ', ' e ', ' I ', ' o ', ' u ', ' a ', ' e ', ' I ', ' o ', ' u '})Ten Vowelset.add (c); One A for(String word:s.split ("")) - { - if(Result.length () > 0) theResult + = ""; - - if(!vowelset.contains (Word.charat (0))) - { +Word = word.substring (1) + word.charat (0); - } + AWord + = "Ma" +addOn; atAddOn + = "a"; - -Result + =Word; - } - - returnresult; in } -}
Reference: N/A
Leetcode List of topics- leetcode Questions List
Title Source: https://leetcode.com/
Leetcode 824. Goat Latin (Goat Latin)