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 ...
随机推荐
- CNN结构:场景分割与Relation Network
参考第一个回答:如何评价DeepMind最新提出的RelationNetWork 参考链接:Relation Network笔记 ,暂时还没有应用到场景中 LiFeifei阿姨的课程:CV与ML课程 ...
- Redis 它是什么?它用来做什么?它的优势与短板如何?
阅读目的: 对什么是内存型数据库有概念性的认知.? Redis 是什么? 通常而言目前的数据库分类有几种,包括 SQL/NSQL,,关系数据库,键值数据库等等 等,分类的标准也不以,Redis本质上也 ...
- Nuxt.js使用详解
首先来讲一下服务端渲染 直白的说就是在服务端拿数据进行解析渲染,直接生成html片段返回给前端.具体用法也有很多种比如: 传统的服务端模板引擎渲染整个页面 服务渲染生成htmll代码块, 前端 AJA ...
- 利用freemarker+SAX解析xml的方式对excel文件字段校验
利用freemarker对参数进行校验这篇文章主要用到的技术点: 自定义注解的使用反射机制SAX解析xmlFreemarker的运用我们在工作中经常需要上传excel文件,然后在对文件中的字段进行校验 ...
- SIGFPE能处理上下溢吗?
SIGFPE可以报告算术异常.包括上下溢.除零等. C标准库说: 各种实现报告的异常类型区别也很大,但几乎没有实现会报告整型溢出. 真的吗?我测试了一下,发现在GCC上,整型.浮点上下溢都不会报告,但 ...
- 最高的奖励 - 优先队列&贪心 / 并查集
题目地址:http://www.51cpc.com/web/problem.php?id=1587 Summarize: 优先队列&贪心: 1. 按价值最高排序,价值相同则按完成时间越晚为先: ...
- mysql运维常用
一.用户授权 用户授权主要指: 1.可以限制用户访问那些库.表 2.可以限制用户对库.表执行select.create.delete.alter.drop等操作 3.可以限制用户登陆的IP.IP段.或 ...
- Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.
在连接数据库时,使用了最新版本的mysql-Connector,所以导致老版本的“com.mysql.jdbc.Drive”不可行,要改为“com.mysql.cj.jdbc.Driver”
- 如何使用微信小程序video组件播放视频
相信很多人都有在手机上看视频的习惯,比较看视频更真实更形象.那么我们在微信小程序中如何观看视频呢?这就需要video组件的帮忙了.今天我们就给大家演示一下,如何用微信小程序组件video播放视频.我们 ...
- Spring 工厂方法创建Bean 学习(三)
1, 静态工厂方法创建Bean 调用静态工厂方法创建 Bean是将对象创建的过程封装到静态方法中. 当客户端需要对象时, 只需要简单地调用静态方法, 而不同关心创建对象的细节. 要声明通过静态方法创建 ...