Python实现 "反转字符串中的元音字母" 的方法
#coding=utf- def reverseVowels(s):
"""
:type s: str
:rtype: str
"""
sStr = list(s)
voList = {'a':, 'A':, 'e':, "E":, 'i':, "I":, 'o':, 'O':, 'u':, 'U':}
front =
length = len(sStr)
back = length -
while front < back:
while front < length and sStr[front] not in voList:
front +=
while back >= and sStr[back] not in voList:
back -=
if front < back:
sStr[front], sStr[back] = sStr[back], sStr[front]
front +=
back -=
return "".join(sStr) str="hello world!"
print(reverseVowels(str))
输出
hollo werld!
或
#coding=utf- def reverseVowels(s):
"""
:type s: str
:rtype: str
"""
sStr = list(s)
voList = {'a':, 'A':, 'e':, "E":, 'i':, "I":, 'o':, 'O':, 'u':, 'U':}
front =
length = len(sStr)
back = length -
while():
while front < length and sStr[front] not in voList:
front +=
while back >= and sStr[back] not in voList:
back -=
if front < back:
sStr[front], sStr[back] = sStr[back], sStr[front]
front +=
back -=
else:
break
return "".join(sStr) str="hello world!"
print(reverseVowels(str))
参考:
https://blog.csdn.net/qiubingcsdn/article/details/82940147
Python实现 "反转字符串中的元音字母" 的方法的更多相关文章
- LeetCode:反转字符串中的元音字母【345】
LeetCode:反转字符串中的元音字母[345] 题目描述 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "h ...
- Java实现 LeetCode 345 反转字符串中的元音字母
345. 反转字符串中的元音字母 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 ...
- Leetcode 345. 反转字符串中的元音字母 By Python
编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: "leet ...
- [Swift]LeetCode345. 反转字符串中的元音字母 | Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...
- 【leetcode 简单】 第八十三题 反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: "leet ...
- 345 Reverse Vowels of a String 反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母.示例 1:给定 s = "hello", 返回 "holle".示例 2:给定 s = "l ...
- leetCode题解之反转字符串中的元音字母
1.问题描述 Reverse Vowels of a String Write a function that takes a string as input and reverse only the ...
- LeetCode--345--反转字符串中的元音字母
问题描述: 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: &quo ...
- C#LeetCode刷题之#345-反转字符串中的元音字母(Reverse Vowels of a String)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3935 访问. 编写一个函数,以字符串作为输入,反转该字符串中的元 ...
随机推荐
- 自学Python编程的第三天----------来自苦逼的转行人
2019-09-14 11:09:50 学Python的第三天和写博客的第三天 本来第三天的内容前天就应该发的,但是因为有点难度,用了两天的时间去学习,按道也是昨天发, 因为中秋导致今天早上发,第三天 ...
- 换个语言学一下 Golang (6)——控制流程
Go语言的控制结构关键字只有if..else if..else ,for 和 switch. 而且在Go中,为了避免格式化战争,对程序结构做了统一的强制的规定.看下下面的例子. 请比较一下A程序和B程 ...
- 二 python并发编程之多进程实现
一 multiprocessing模块介绍 二 process类的介绍 三 process类的使用 四 守护进程 五 进程同步(锁) 六 队列 七 管道 八 共享数据 九 信号量 十 事件 十一 进程 ...
- CGContextRef&CGMutablePathRef&UIBezierPath简单学习
简单的四句介绍 Quartz是一个二维绘图引擎,使用的是CoreGraphics库,同时支持iOS和Mac系统 CGContextRef:获取图形上下文.或者叫作用域,即画布,他是专门用来保存绘画期间 ...
- 获取form表单默认提交的返回值
1.经常用form表单提交的小伙伴有没有发现,form表单默认的提交是没有返回值的,而且默认提交成功之后是跳转,跳转的action的路径,下面写一下默认的提交如何获取到form表单的返回值json,并 ...
- 英语DYAMAUND钻石DYAMAUND单词
dyamaund and the English words dyamaund The Vertu of the Dyamaund": Gemstones, Knowledge and Va ...
- VSCode 控制台面板输出乱码 字符编码问题 PHP --已解决
首先上一张效果图,看看是不是你想要的效果. 第一步: 按F1,输入settings.json,添加 "code-runner.runInTerminal": true, 第二步:将 ...
- Node: 模块
我们知道,Node.js 选用 JavaScript 语言来编写代码.JavaScript 这门语言呢,之前主要用于前端应用,并没有相应的模块管理功能,而是以 script 标签为单位,直接引入即可运 ...
- JQuery中两个ul标签的li互相移动
实例 <html > <head> <meta http-equiv="Content-Type" content="text/html; ...
- 事务@Transactional
在service类前加上@Transactional,声明这个service所有方法需要事务管理.每一个业务方法开始时都会打开一个事务. Spring默认情况下会对运行期例外(RunTimeExcep ...