编写一个函数,以字符串作为输入,反转该字符串中的元音字母。

示例 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 简单】 第八十三题 反转字符串中的元音字母的更多相关文章

  1. LeetCode:反转字符串中的元音字母【345】

    LeetCode:反转字符串中的元音字母[345] 题目描述 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "h ...

  2. Java实现 LeetCode 345 反转字符串中的元音字母

    345. 反转字符串中的元音字母 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 ...

  3. Leetcode 345. 反转字符串中的元音字母 By Python

    编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: "leet ...

  4. [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 ...

  5. 345 Reverse Vowels of a String 反转字符串中的元音字母

    编写一个函数,以字符串作为输入,反转该字符串中的元音字母.示例 1:给定 s = "hello", 返回 "holle".示例 2:给定 s = "l ...

  6. [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 ...

  7. leetCode题解之反转字符串中的元音字母

    1.问题描述 Reverse Vowels of a String Write a function that takes a string as input and reverse only the ...

  8. Python实现 "反转字符串中的元音字母" 的方法

    #coding=utf- def reverseVowels(s): """ :type s: str :rtype: str """ sS ...

  9. C#LeetCode刷题之#345-反转字符串中的元音字母​​​​​​​(Reverse Vowels of a String)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3935 访问. 编写一个函数,以字符串作为输入,反转该字符串中的元 ...

随机推荐

  1. windows多线程(四) 关键段 CriticalSection

    一.问题回顾 我们上一篇文章最后的程序的输出 g_Count 的值不是每次都正确,原因是没有对全局资源 g_Count 进行互斥访问(就是同一时刻只能由一个线程访问),接下来我们就来说一下使用关键段来 ...

  2. Intellij IDEA Scala开发环境搭建

    1,在intellij 官网上下载IDEA 2,在scala官网上下载最新版scala 3,安装两个下载的文件 4,打开intellij,菜单栏help->find action   输入plu ...

  3. nodejs 新特性

    一般时间没看nodejs了,又出了一些新特性了. 异步钩子     async_hooks      先看相关的文章吧 https://zhuanlan.zhihu.com/p/27394440 性能 ...

  4. SpringBoot(十二)_springboot整合PageHelper

    我之所以会发现这个PageHelper这个东东 是因为公司在使用 ,刚开始我也没太注意这个插件,感觉不就是个分页插件吗?也就那样,直到一天,我在网上找了个代码生成器,用来构建代码,因为它是针对mysq ...

  5. UpdateBatch到底是怎么用的?

    要使用ADOQuery的UpdateBatch函数,必须将ADOQuery的LockType属性设置成ltBatchOptimistic

  6. 深入理解JAVA虚拟机阅读笔记3——垃圾回收器

    一.垃圾收集器总览 新生代:Serial. ParNew. Parallel Scavenge 老年代:CMS.Serial Old. Parallel Old 最新的:G1 并行和并发的区别: 并行 ...

  7. QString,string,char* 在utf8和gbk不同编码下的相互转化

    关于编码简介:ascii编码是最开始的编码规则本,里面只收纳了英文.特殊字符.数字等有限字符,采用的是8位一个字节的方式进行编码对照:unicode在ascii码的基础上进行了升级扩展,立志将全世界所 ...

  8. centOS基本操作和命令(更新)

    1.文字输入和图形界面切换 CTRL+ALT+(F1~F6)为切换至文字输入,分别对应六个不同输入界面,可用以不同账号:CTRL+ALT+F7为切换至图形界面 2.修改时区 date -R date ...

  9. Linux下的bash对拍

    下面是Linux下的bash对拍程序: #!/bin/bash t=0 //数据组数 while true; do let "t=$t + 1" echox printf $t / ...

  10. Luogu 2801 教主的魔法 | 分块模板题

    Luogu 2801 教主的魔法 | 分块模板题 我犯的错误: 有一处l打成了1,还看不出来-- 缩小块大小De完bug后忘了把块大小改回去就提交--还以为自己一定能A了-- #include < ...