[LeetCode] 824. Goat Latin_Easy
A sentence S
is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.
We would like to convert the sentence to "Goat Latin" (a made-up language similar to Pig Latin.)
The rules of Goat Latin are as follows:
- If a word begins with a vowel (a, e, i, o, or u), append
"ma"
to the end of the word.
For example, the word 'apple' becomes 'applema'. - If a word begins with a consonant (i.e. not a vowel), remove the first letter and append it to the end, then add
"ma"
.
For example, the word"goat"
becomes"oatgma"
. - Add one letter
'a'
to the end of each word per its word index in the sentence, starting with 1.
For example, the first word gets"a"
added to the end, the second word gets"aa"
added to the end and so on.
Return the final sentence representing the conversion from S
to Goat Latin.
Example 1:
Input: "I speak Goat Latin"
Output: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"
Example 2:
Input: "The quick brown fox jumped over the lazy dog"
Output: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"
Notes:
S
contains only uppercase, lowercase and spaces. Exactly one space between each word.1 <= S.length <= 150
.
Code
class Solution:
def toGoatLatin(self, S):
ans = S.split()
for index, word in enumerate(ans):
if word[0] not in "aeiouAEIOU":
ans[index] = word[1:] + word[0]
ans[index] += 'ma' + 'a'*(index+1)
return " ".join(ans)
[LeetCode] 824. Goat Latin_Easy的更多相关文章
- 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 (山羊拉丁文)
题目标签:String 首先把vowel letters 保存入 HashSet. 然后把S 拆分成 各个 word,遍历每一个 word: 当 word 第一个 字母不是 vowel 的时候,把第一 ...
- [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 ...
- Java实现 LeetCode 824 山羊拉丁文(暴力)
824. 山羊拉丁文 给定一个由空格分割单词的句子 S.每个单词只包含大写或小写字母. 我们要将句子转换为 "Goat Latin"(一种类似于 猪拉丁文 - Pig Latin ...
- 824. Goat Latin山羊拉丁文
[抄题]: A sentence S is given, composed of words separated by spaces. Each word consists of lowercase ...
随机推荐
- Zookeeper中Session Timeout的那些事
前言: RDS系统致力于MySQL数据的高可用,高可靠,高性能以及在线扩展功能,实现这些特性的主要逻辑功能都运行在管理服务器上,一旦管理服务器宕机,数据库的在线扩展功能/备份功能/故障恢复功能等都无从 ...
- 进程池的map方法
from multiprocessing import Process,Pool def f1(n): for i in range(10): n = n+1 if __name__ == ...
- [No0000F1]js获取喜马拉雅和荔枝FM电台专辑音频
荔枝FM小书签.txt javascript: (function() { if ($('#down_url')) { $('#down_url').remove(); }; $(document.b ...
- GPU安装小结
今天一起安装了4块1080的卡.也算有一些坑吧,记录一下. 1)1080显卡,驱动型号,tensorflow,cuda, cudnn 版本一定要一致.我的清单如下: ################# ...
- 最全最详细:ubuntu16.04下linux内核编译以及设备驱动程序的编写(针对新手而写)
写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...
- lsof and dynamic array in bash/shell
https://unix.stackexchange.com/questions/171519/lsof-warning-cant-stat-fuse-gvfsd-fuse-file-system F ...
- 2018/05/02 PHP 之错误与异常处理
在学习中,越学习越觉得自己基础薄弱. 在平常工作中,对于某些错误处理感觉不知道怎么下手,于是决定重新再整理一下. 强烈推荐这篇文章,真的感觉学习到了很多. 部分引用::再谈PHP错误与异常处理 -- ...
- ECharts图形库
ECharts图形库百度的项目,图形的创建也比较简单,直接引用Javascript即可 1,引入<script src="{{ url_for("static",f ...
- u-boot 编译,启动流程分析,移植
分析u-boot-1.1.6 的启动流程 移植u-boot 2012.04版本到JZ2440开发板 源码百度云链接:https://pan.baidu.com/s/10VnxfDWBqJVGY3SCY ...
- Asp.net Mvc action返回多个模型实体给view
1.controller中action代码: public class HomeController : Controller { public ActionResult Detail(int id) ...