|
| 1 | +<p>You are given a string <code>sentence</code> that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only.</p> |
| 2 | + |
| 3 | +<p>We would like to convert the sentence to "Goat Latin" (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>If a word begins with a vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, or <code>'u'</code>), append <code>"ma"</code> to the end of the word. |
| 7 | + |
| 8 | + <ul> |
| 9 | + <li>For example, the word <code>"apple"</code> becomes <code>"applema"</code>.</li> |
| 10 | + </ul> |
| 11 | + </li> |
| 12 | + <li>If a word begins with a consonant (i.e., not a vowel), remove the first letter and append it to the end, then add <code>"ma"</code>. |
| 13 | + <ul> |
| 14 | + <li>For example, the word <code>"goat"</code> becomes <code>"oatgma"</code>.</li> |
| 15 | + </ul> |
| 16 | + </li> |
| 17 | + <li>Add one letter <code>'a'</code> to the end of each word per its word index in the sentence, starting with <code>1</code>. |
| 18 | + <ul> |
| 19 | + <li>For example, the first word gets <code>"a"</code> added to the end, the second word gets <code>"aa"</code> added to the end, and so on.</li> |
| 20 | + </ul> |
| 21 | + </li> |
| 22 | +</ul> |
| 23 | + |
| 24 | +<p>Return<em> the final sentence representing the conversion from sentence to Goat Latin</em>.</p> |
| 25 | + |
| 26 | +<p> </p> |
| 27 | +<p><strong class="example">Example 1:</strong></p> |
| 28 | +<pre><strong>Input:</strong> sentence = "I speak Goat Latin" |
| 29 | +<strong>Output:</strong> "Imaa peaksmaaa oatGmaaaa atinLmaaaaa" |
| 30 | +</pre><p><strong class="example">Example 2:</strong></p> |
| 31 | +<pre><strong>Input:</strong> sentence = "The quick brown fox jumped over the lazy dog" |
| 32 | +<strong>Output:</strong> "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa" |
| 33 | +</pre> |
| 34 | +<p> </p> |
| 35 | +<p><strong>Constraints:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li><code>1 <= sentence.length <= 150</code></li> |
| 39 | + <li><code>sentence</code> consists of English letters and spaces.</li> |
| 40 | + <li><code>sentence</code> has no leading or trailing spaces.</li> |
| 41 | + <li>All the words in <code>sentence</code> are separated by a single space.</li> |
| 42 | +</ul> |
0 commit comments