题目标签: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

 class Solution
{
public String toGoatLatin(String S)
{
String result = "";
Set<Character> vowelSet = new HashSet<>();
String addOn = "a"; for (char c: new char[]{'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'})
vowelSet.add(c); for(String word : S.split(" "))
{
if(result.length() > 0)
result += " "; if(!vowelSet.contains(word.charAt(0)))
{
word = word.substring(1) + word.charAt(0);
} word += "ma" + addOn;
addOn += "a"; result += word;
} return result;
}
}

参考资料:N/A

LeetCode 题目列表 - LeetCode Questions List

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

LeetCode 824. Goat Latin (山羊拉丁文)的更多相关文章

  1. 824. Goat Latin山羊拉丁文

    [抄题]: A sentence S is given, composed of words separated by spaces. Each word consists of lowercase ...

  2. [LeetCode] Goat Latin 山羊拉丁文

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

  3. Leetcode824.Goat Latin山羊拉丁文

    给定一个由空格分割单词的句子 S.每个单词只包含大写或小写字母. 我们要将句子转换为 "Goat Latin"(一种类似于 猪拉丁文 - Pig Latin 的虚构语言). 山羊拉 ...

  4. LeetCode 824 Goat Latin 解题报告

    题目要求 A sentence S is given, composed of words separated by spaces. Each word consists of lowercase a ...

  5. [LeetCode] 824. Goat Latin

    Description A sentence S is given, composed of words separated by spaces. Each word consists of lowe ...

  6. 824. Goat Latin - LeetCode

    Questioin 824. Goat Latin Solution 题目大意:根据要求翻译句子 思路:转换成单词数组,遍历数组,根据要求转换单词 Java实现: 用Java8的流实现,效率太低 pu ...

  7. 【Leetcode_easy】824. Goat Latin

    problem 824. Goat Latin solution class Solution { public: string toGoatLatin(string S) { unordered_s ...

  8. 【LeetCode】824. Goat Latin 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  9. [LeetCode&Python] Problem 824. Goat Latin

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

随机推荐

  1. sql server truncate table 删除表数据限制条件

    truncate 注释 注释TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行.但 TRUNCATE TABLE 比 DELETE 速度快 ...

  2. JavaScript 单例,Hash,抛异常

    1. 单例 ECMA 5 版 记得以前写过几种单例实现,找不到了... function Singleton() { if (this.constructor.instance) { return t ...

  3. Flask框架 之abort、自定义错误、视图函数返回值与jsonify

    一.abort函数 使用abort函数可以立即终止视图函数的执行,并可以返回给前端特定的值. abort函数的作用: 1.传递状态码,必须是标准的http状态码 2.传递响应体信息 @app.rout ...

  4. CAD控件:网上打开dwg文件时,对dwg文件路径加密的功能

    梦想CAD控件2015.03.12最新更新  1. 增加控件状态栏文字,自定义功能,        C++接口为 :   CStatusBarInformationReactor::CreatePro ...

  5. JSON字符串的生成

    public class Corporation { public string remark { get; set; } public string version { get; set; } pu ...

  6. PrintWriter与ServletOutputStream的区别之文件下载

    copy自:https://blog.csdn.net/weixin_37703598/article/details/803870611.out = response.getWriter(); re ...

  7. STL++?pb_ds平板电视初步探索

    什么是pb_ds? 除了众所周知的STL库,c++还自带了ext库(应该可以这么叫吧),其中有用pb_ds命名的名称空间(俗称平板电视).这个名称空间下有四个数据类型结构.这些都是鲜为人知的.经过测试 ...

  8. Linux下常用的操作

    Linux下常用的操作 文件定位 locate filename 有些版本的linux会出现 -bash: locate: command not found错误,不要慌,安装一下mlocate包就好 ...

  9. python3 时间模块 random模块之两个小练习

    话不多说,一个是算时间的,还有一个是生成验证码的 #!usr/bin/env/ python # -*- coding:utf-8 -*- # Author: XiaoFeng import time ...

  10. 3. Python中的分支判断、循环

    本文利用的是Python 3.x版本,建议学习3.x版本 Python中的分支判断.循环 1. 分支条件判断 1.1 比较操作 以下是数之间常见的比较操作,例如5>3就是数学意义上的比较,5是大 ...