zoukankan      html  css  js  c++  java
  • LeetCode 824. Goat Latin (山羊拉丁文)

    题目标签:String

     首先把vowel letters 保存入 HashSet。

       然后把S 拆分成 各个 word,遍历每一个 word:

       当 word 第一个 字母不是 vowel 的时候,把第一个char 加到最后;

       然后添加“ma” 和 “a“ 到最后;

       添加新的"a";

       把新的 word 加入 result,还要记得加入空格。

    Java Solution:

    Runtime beats 62.66% 

    完成日期:10/12/2018

    关键词:String

    关键点:利用HashSet保存vowel 

     1 class Solution 
     2 {
     3     public String toGoatLatin(String S) 
     4     {
     5         String result = "";
     6         Set<Character> vowelSet = new HashSet<>();
     7         String addOn = "a";
     8         
     9         for (char c: new char[]{'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'})
    10             vowelSet.add(c);
    11         
    12         for(String word : S.split(" "))
    13         {
    14             if(result.length() > 0)
    15                 result += " ";
    16             
    17             if(!vowelSet.contains(word.charAt(0)))
    18             {
    19                 word = word.substring(1) + word.charAt(0);
    20             }
    21             
    22             word += "ma" + addOn;
    23             addOn += "a";
    24             
    25             result += word;
    26         }
    27         
    28         return result;
    29     }
    30 }

    参考资料:N/A

    LeetCode 题目列表 - LeetCode Questions List

    题目来源:https://leetcode.com/

  • 相关阅读:
    Go strings.Builder
    httprouter使用pprof
    大规模分布式系统的跟踪系统
    Yearning 介绍(SQL审核平台)
    Inception介绍(MySQL自动化运维工具)
    go 学习资源和GitHub库
    go 命令
    Redash 安装部署
    systemd 编写
    查看mysql 版本
  • 原文地址:https://www.cnblogs.com/jimmycheng/p/9784936.html
Copyright © 2011-2022 走看看