Leetcode 824. Goat Latin (Goat Latin)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.