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爬虫+颜值打分,5000+图片找到你的Mrs. Right
一见钟情钟的不是情,是脸 日久生情生的不是脸,是情 项目简介 本项目利用Python爬虫和百度人脸识别API,针对简书交友专栏,爬取用户照片(侵删),并进行打分. 本项目包括以下内容: 图片爬 ...
- 浏览器的两种模式quirks mode 和strict mode
关键字: javascript.quirks mode.strict mode 在看js代码时,有时会看到关于quirks mode(怪异模式)和strict mode(严格格式)的东西,一直也没深究 ...
- DeepMind:所谓SACX学习范式
机器人是否能应用于服务最终还是那两条腿值多少钱,而与人交互,能真正地做"服务"工作,还是看那两条胳膊怎么工作.大脑的智能化还是非常遥远的,还是先把感受器和效应器做好才是王道. 关于 ...
- oracle数据库过期
本文转载自http://soft.chinabyte.com/database/6/12320006.shtml[来源:比特网 作者:悠虎] 由于Oracle11G的新特性所致,经常会遇到使用sqlp ...
- Win7访问不了WINXP共享文件
用win xp的机器可以访问,但用win 7的机器无法访问共享文件 提示:您没有权限访问.请与网络管理员联系请求访问权限 网上找了相应的资料 做了如下动作 1. 打开网上邻居→本地连接→属性里,“看是 ...
- sort 排序 自定义排序算法的使用
// struct sort_by_pt// {// bool operator()(const std::pair<CString, AcGePoint3d> a, const std: ...
- 16 this和super和构造代码块
this关键词---当前类的对象的引用 public class Public { String name; int age; public static void main(String[] arg ...
- 【LeetCode】7、Reverse Integer(整数反转)
题目等级:Easy 题目描述: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 O ...
- HTML5 实现Link跳线效果
之前我们推出过Flex版本的Link跳线效果,现在基于HTML5新版本的跳线效果也实现了,细微之处我们进行了改进,如link倾斜的时候Offset方向始终保持垂直等.先看效果.实现的算法和Flex基本 ...
- P1048 采药
题目描述 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给他出了一个难题.医师把他带到一个到处都是草药的山洞里对他说:“孩子,这个 ...