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
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 (山羊拉丁文)的更多相关文章
- 824. Goat Latin山羊拉丁文
[抄题]: A sentence S is given, composed of words separated by spaces. Each word consists of lowercase ...
- [LeetCode] Goat Latin 山羊拉丁文
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...
- Leetcode824.Goat Latin山羊拉丁文
给定一个由空格分割单词的句子 S.每个单词只包含大写或小写字母. 我们要将句子转换为 "Goat Latin"(一种类似于 猪拉丁文 - Pig Latin 的虚构语言). 山羊拉 ...
- LeetCode 824 Goat Latin 解题报告
题目要求 A sentence S is given, composed of words separated by spaces. Each word consists of lowercase a ...
- [LeetCode] 824. Goat Latin
Description A sentence S is given, composed of words separated by spaces. Each word consists of lowe ...
- 824. Goat Latin - LeetCode
Questioin 824. Goat Latin Solution 题目大意:根据要求翻译句子 思路:转换成单词数组,遍历数组,根据要求转换单词 Java实现: 用Java8的流实现,效率太低 pu ...
- 【Leetcode_easy】824. Goat Latin
problem 824. Goat Latin solution class Solution { public: string toGoatLatin(string S) { unordered_s ...
- 【LeetCode】824. Goat Latin 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [LeetCode&Python] Problem 824. Goat Latin
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...
随机推荐
- Python学习日记之快捷键
Alt+Enter 自动添加包Ctrl+t SVN更新Ctrl+k SVN提交Ctrl + / 注释(取消注释)选择的行Ctrl+Shift+F 高级查找Ctrl+Enter 补全Shift + En ...
- Farseer.net轻量级开源框架 中级篇:执行SQL语句
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: 事务的使用 下一篇:Farseer.net轻量级开源框架 中级篇: DbFacto ...
- vue路由传参(学习心得)
如果组件通过query来传递num参数为1,相当与在 url 地址后面拼接参数 <template> <div> <h3>首页</h3> <rou ...
- dubbo-monitor安装及配置过程
安装 1. 使用git下载(git clone https://github.com/alibaba/dubbo.git)或者从http://dubbo.io/下载源码 2. cd到dubbo的根目录 ...
- HTML `capture` 属性
file 类型的 <input> 除了调起系统的文件选择框外,还可通过指定 capture 属性来现场拍照或录制.配合 accept 属性,可实现更加便捷的文件获取. 比如想要录制一段视频 ...
- jenkins自动部署测试环境
构建脚本如下: echo "当前目录":$(pwd)echo "当前时间":$(date +%Y-%m-%d_%H:%M)find ./ -type f -na ...
- error: Bean property 'userDAO' is not writable or has an invalid setter method.
使用Spring属性注入的方式,没有在ServiceImpl中setDao,导致程序报错 public class AddressServiceImpl implements IAddressServ ...
- 「 Luogu P2230 」X 「 Vijos 1142 」 HXOS系统
题目描述可能稍有偏差,但实质上是一样的. 看下面 题目大意 题面这么长,先说说题意吧. 就是有一个操作系统,他的存储方式是树形的.其中分为文件和目录(文件夹)每一个子目录下只能存储 $K$ 个文件或目 ...
- 面试总结——Java高级工程师(二)
一.Java底层基础题 1.SpringMVC的原理以及返回数据如何渲染到jsp/html上? 答:Spring MVC的核心就是 DispatcherServlet , 一个请求经过 Dispatc ...
- Haoop Mapreduce 中的FileOutputFormat类
FileOutputFormat类继承OutputFormat,需要提供所有基于文件的OutputFormat实现的公共功能,主要有以下两点: (1)实现checkOutputSpecs方法 chec ...