国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[LeetCode] 824. Goat Latin

coolpail / 1775人閱讀

Problem (and this is a very stupid problem...)

A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.

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:

If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end of the word.
For example, the word "apple" becomes "applema".

If a word begins with a consonant (i.e. not a vowel), remove the first letter and append it to the end, then add "ma".
For example, the word "goat" becomes "oatgma".

Add one letter "a" to the end of each word per its word index in the sentence, starting with 1.
For example, the first word gets "a" added to the end, the second word gets "aa" added to the end and so on.
Return the final sentence representing the conversion from S to Goat Latin.

Example 1:

Input: "I speak Goat Latin"
Output: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"

Example 2:

Input: "The quick brown fox jumped over the lazy dog"
Output: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"
 

Notes:

S contains only uppercase, lowercase and spaces. Exactly one space between each word.
1 <= S.length <= 150.

Solution
class Solution {
    public String toGoatLatin(String S) {
        String[] words = S.split(" ");
        String as = "";
        StringBuilder sb = new StringBuilder();
        Set vowel = new HashSet<>();
        vowel.add("a");
        vowel.add("e");
        vowel.add("i");
        vowel.add("o");
        vowel.add("u");
        vowel.add("A");
        vowel.add("E");
        vowel.add("I");
        vowel.add("O");
        vowel.add("U");
        for (int i = 0; i < words.length; i++) {
            as += "a";
            char first = words[i].charAt(0);
            if (vowel.contains(first)) {
                sb.append(words[i]+"ma"+as+" ");
            } else {
                sb.append(words[i].substring(1)+first+"ma"+as+" ");
            }
        }
        return sb.toString().trim();
    }
}

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/77266.html

相關文章

  • Leetcode PHP題解--D60 824. Goat Latin

    摘要:題目鏈接題目分析給定一個句子,由大小寫英文字母組成,以空格為單詞的分割。即,在第個單詞按以上規則轉換完成后,再加個。分割后,判斷首字母是否不是元音。不是元音,則將第一個字母移到最后。給字符串末尾添加。 D60 824. Goat Latin 題目鏈接 824. Goat Latin 題目分析 給定一個句子,由大小寫英文字母組成,以空格為單詞的分割。 按以下規則修改單詞: 如果一個單詞...

    xorpay 評論0 收藏0
  • export和import的用法總結

    摘要:把直接加到聲明前面就可以省略無論怎樣輸出,輸入的時候都需要。其實這種導出方式可以看成是命名導出的變種,只不過把命名寫成了。對應輸入的例子參考文章詳解中與的用法和區別我在 ES6中export一般的用法有兩種 命名導出(Named exports) 默認導出(Default exports) 命名導出(Named exports) 就是每一個需要輸出的數據類型都要有一個name,統一...

    EasonTyler 評論0 收藏0
  • ZooKeeper 學習筆記

    摘要:與此同時,小組也一同致力于項目,參與了很多動物命名的項目,其中有廣為人知的項目。主控服務器將所有更新操作序列化,利用協議將數據更新請求通知所有從屬服務器,保證更新操作。在術語下,節點被稱為。命名為的,由系統自動生成,用配額管理。 ZooKeeper 介紹 ZooKeeper(wiki,home,github) 是用于分布式應用的開源的分布式協調服務。通過暴露簡單的原語,分布式應用能在之...

    funnyZhang 評論0 收藏0

發表評論

0條評論

coolpail

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<