成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

[LeetCode] 824. Goat Latin

coolpail / 1782人閱讀

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();
    }
}

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/77266.html

相關(guān)文章

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

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

    xorpay 評論0 收藏0
  • export和import的用法總結(jié)

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

    EasonTyler 評論0 收藏0
  • ZooKeeper 學(xué)習(xí)筆記

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

    funnyZhang 評論0 收藏0

發(fā)表評論

0條評論

coolpail

|高級講師

TA的文章

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