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 ...
随机推荐
- App保持登录状态的常用方法
我们在使用App时,一次登录后App如果不主动退出登录或者清除数据,App会在很长一段时间内保持登录状态,或者让用户感觉到登录一次就不用每次都输入用户密码才能进行登录.银行.金融涉及到支付类的App一 ...
- 联想 Vibe Shot(Z90-3) 免recovery 获取ROOT权限 救砖 VIBEUI V3.1_1625
>>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...
- 带有空格或tab的字符串的判断
class test { public static void main(String[] args) { String a = " "; //带有空格的字符串 if ( a.is ...
- 基于C++的多态性动态判断函数
这里先有一个问题: 问题描述:函数int getVertexCount(Shape * b)计算b的顶点数目,若b指向Shape类型,返回值为0:若b指向Triangle类型,返回值为3:若b指向Re ...
- 《网络管理》IP地址管理与子网划分
IP地址管理——ipmaster ipmaster是一款对IP地址进行管理的软件,使用该软件可以提高网络管理员的工作效率.在大型网络中,使用该软件可以有序且高效地实现大中小型企业网IP地址的分配和管理 ...
- Understanding and Analyzing Application Crash Reports
Introduction When an application crashes, a crash report is created and stored on the device. Crash ...
- 习题练习(视觉slam14讲课后习题)
设有⼩萝⼘1⼀号和⼩萝⼘⼆号位于世界坐标系中. ⼩萝⼘⼀号的位姿为:q1 = [0.55, 0.3, 0.2, 0.2], t1 = [0.7, 1.1, 0.2]T(q 的第⼀项为实部).这⾥的 q ...
- Monkey进行测试时如何屏蔽掉状态栏和音量键
我在学习的过程中使用简单的点击命令总是会触发到音量键和状态栏,由于我的测试机是虚拟按键所以也会触碰到 接下来说一下解决办法 全屏状态 adb shell settings put global po ...
- HDU4496 D-City【基础并查集】
Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to ...
- centOS目录结构介绍
Linux / CentOS目录结构 /: 根目录,一般根目录下只存放目录,不要存放文件,/etc./bin./dev./lib./sbin应该和根目录放置在一个分区中 /bin:/usr/bin: ...