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 访问. 编写一个函数,以字符串作为输入,反转该字符串中的元 ...
随机推荐
- [golang]图片按中心旋转后,新图的左顶点位置的偏移量
1 前言 图片按中心旋转后,新图的左顶点位置的偏移量 2 代码 func OffsetXYAfterRotationCore(W, H, L, T, Angle float64) (x, y floa ...
- springboot项目,打包时携带所有依赖
springboot项目,打包时携带所有依赖 本文主要解决springboot打包时,如何设置才能把当前项目的所有依赖都打进去. Springboot 的自带spring-boot-maven-plu ...
- MySQLNonTransientConnectionException: Could not create connection to database server.
MySQLNonTransientConnectionException: Could not create connection to database server. Spring整合mybati ...
- 直播知识-推流&拉流
推流,指的是把采集阶段封包好的内容传输到服务器的过程.其实就是将现场的视频信号传到网络的过程.“推流”对网络要求比较高,如果网络不稳定,直播效果就会很差,观众观看直播时就会发生卡顿等现象,观看体验很是 ...
- Python使用numpy进行数据转换
一.测试数据 二.代码实现 # -*- coding: utf-8 -*- """ Created on Sun Jul 7 11:35:01 2019 加载数据时对指定 ...
- tmp-scmj
1.apk下载 http://app6.wpf2x4.cn/?downloadfrom=sichuan 麻将图: Big_mahjonghn_tiles_sr.png
- day 03 作业 预科
目录 作业 1.简述变量的组成 2.简述变量名的命名规范 3.简述注释的作用 4.使用turtle库构造一幅图,贴在markdown文档中 作业 1.简述变量的组成 变量由变量名.赋值符号.变量值所组 ...
- MySQL用户与权限
用户连接到mysql,并做各种查询,在用户和服务器中间分为两个阶段: 1:用户是否有权连接上来 2:用户是否有权执行此操作(如select,update等等) 先看第一个阶段:服务器如何判断用户是否有 ...
- 【HCIA Gauss】学习汇总-数据库管理(事务 权限 审计 OBDC JDBC)-6
事务控制事务提交 commit事务回滚 rollback savepoint 用于事务设置保存点 ----> savepoint s1 / savepoint s2 rollback to sa ...
- ztree根据关键字模糊搜索
html页面需要引入以下资源 <!-- jquery包,ztree依赖jquery --> <script type="text/javascript" src= ...