【leetcode 简单】 第八十三题 反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
输入: "hello"
输出: "holle"
示例 2:
输入: "leetcode"
输出: "leotcede"
说明:
元音字母不包含字母"y"。
class Solution:
def reverseVowels(self, s):
"""
:type s: str
:rtype: str
"""
start = 0
end = len(s)-1
if end <= start:
return s
tmp = list(s)
limit = 'aeiouAEIOU'
while start < end:
if tmp[start] not in limit:
start += 1
elif tmp[end] not in limit:
end -= 1
else:
tmp[start],tmp[end]=tmp[end],tmp[start]
start += 1
end -= 1
return ''.join(tmp)
【leetcode 简单】 第八十三题 反转字符串中的元音字母的更多相关文章
- 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 ...
- 345 Reverse Vowels of a String 反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母.示例 1:给定 s = "hello", 返回 "holle".示例 2:给定 s = "l ...
- [LeetCode] Reverse Vowels of a String 翻转字符串中的元音字母
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- leetCode题解之反转字符串中的元音字母
1.问题描述 Reverse Vowels of a String Write a function that takes a string as input and reverse only the ...
- Python实现 "反转字符串中的元音字母" 的方法
#coding=utf- def reverseVowels(s): """ :type s: str :rtype: str """ sS ...
- C#LeetCode刷题之#345-反转字符串中的元音字母(Reverse Vowels of a String)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3935 访问. 编写一个函数,以字符串作为输入,反转该字符串中的元 ...
随机推荐
- php父级目录文件包函问题
问题: php子目录不能包函父目录中的文件. 环境: 网站根目录:/var/www/html/ PHP版本: 5.3.3 Apache版本:2.2 好了,创建三个文件: //文件路径:/var/www ...
- 2013长沙网赛E题Travel by Bike
题目链接:http://acm.zju.edu.cn/changsha/showProblem.do?problemId=26 题意:一个人从一个地方到另一个地方,长度为L,每小时速度为speed,周 ...
- 在Asp.Net Core中使用Session
1.在Stratup.cs中配置Session public void ConfigureServices(IServiceCollection services) { services.AddSes ...
- todomvc-app
1.HTML <!doctype html> <html lang="en"> <head> <meta charset="ut ...
- python的N个小功能(找到要爬取的验证码链接,并大量下载验证码样本)
# -*- coding: utf-8 -*- """ Created on Mon Mar 21 11:04:54 2017 @author: sl "&qu ...
- List of NP-complete problems
This is a list of some of the more commonly known problems that are NP-complete when expressed as de ...
- Express入门( node.js Web应用框架 )
运用Express框架构建简单的NodeJS应用 Start 确认安装了NodeJS之后(最新的Node安装好后NPM也会自带安装了),npm可理解为nodejs的一个工具包.可通过查看版本来检测是 ...
- UESTC--1468
题目:A Coin Problem 原题链接:http://acm.uestc.edu.cn/problem.php?pid=1468 分析:满足裴波纳契数列,打表找周期. #include<i ...
- python print end=' ' 不换行
python3.x 实现print 不换行 python中print之后是默认换行的,是因为其默认属性 end 默认值为"\n"(\n为换行符). 做练习99乘法表时不想换行,改变 ...
- poj 3685 二分
Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7415 Accepted: 2197 Descriptio ...