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 访问. 编写一个函数,以字符串作为输入,反转该字符串中的元 ...
随机推荐
- Hibernate的关联映射--一对多、
这是我 1 单向一对多: 实体类:(课程类)Grade与(学生类)Student的一对多关系 学生类: public class Student implements java.io.Serializ ...
- Git查看文件制定行区间的提交记录
git blame -L , /dir/file/file.php 这里查看file文件下6610至6613行的修改记录
- mvc和mvvm模式
一. Mvvm定义 MVVM是Model-View-ViewModel的简写.即模型-视图-视图模型.[模型]指的是后端传递的数据.[视图]指的是所看到的页面.[视图模型]mvvm模式的核心,它是连接 ...
- 调用Hybris API时遇到的错误消息Cannot find user with uid如何解决
今天工作中试图调用Commerce Cloud的user creation API用代码创建Hybris用户时,遇到下面这个错误消息. 我觉得很奇怪,因为backoffice里能查到这个id为jerr ...
- DOS命令_查询某个端口的占用情况并释放
>netstat -aon | findstr “80″Proto Local Address Foreign Address State ...
- 如何使用Fiddler抓取APP接口和微信授权网页源代码
Fiddler,一个抓包神器,不仅可以通过手机访问APP抓取接口甚至一些数据,还可以抓取微信授权网页的代码. 下载安装 1. 下载地址(官网): https://www.telerik.com/do ...
- Walle实现自动发布
walle是啥?能干啥?有啥用?这些我都不会去一一道来,如果你还没有明白前面提出的三个问题就不用往下看了,这里这回将walle安装了怎么去使用.如果都要面面俱到不是一两篇博客可以解决的问题,如果希望将 ...
- 基于TCP协议的远程终端控制并发socketserver实现以及粘包问题处理
# 客户端 # -*- coding: utf-8 -*- import socketserver import struct import json import subprocess class ...
- USB之hub3
============= 本系列参考 ============= <圈圈教你玩USB>.<Linux那些事儿之我是USB> 协议文档:https://www.usb.or ...
- Guava Cache 工具类
maven依赖 <dependency> <groupId>com.google.guava</groupId> <artifactId>guava&l ...