345. Reverse Vowels of a String*
来源:互联网 发布:淘宝模特快速摆拍 编辑:程序博客网 时间:2024/06/05 08:23
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
Note:
The vowels does not include the letter "y".
My code
class Solution(object): def reverseVowels(self, s): """ :type s: str :rtype: str """ vowelList=['A','a','O','o','E','e','I','i','U','u'] lowIndex = 0 highIndex = len(s)-1 s= list(s) while lowIndex<=highIndex: if s[lowIndex] in vowelList and s[highIndex] in vowelList: s[lowIndex],s[highIndex]=s[highIndex],s[lowIndex] lowIndex +=1 highIndex -=1 elif s[lowIndex] not in vowelList and s[highIndex] in vowelList: lowIndex +=1 elif s[lowIndex] in vowelList and s[highIndex] not in vowelList: highIndex -=1 else: lowIndex +=1 highIndex -=1 return ('').join(s)Notes:
s[lowIndex],s[highIndex]=s[highIndex],s[lowIndex]
('').join(s
0 0
- String:345. Reverse Vowels of a String
- 345. Reverse Vowels of a String 【E】
- LeetCode 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- leetcode-345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- #leetcode#345. Reverse Vowels of a String
- [leetcode] 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- Leetcode:345. Reverse Vowels of a String
- LeetCode *** 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- LeetCode.345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- Android ListView工作原理完全解析,带你从源码的角度彻底理解
- leetcode/344. Reverse String
- Axel多线程下载工具使用详解
- Android View的Measure过程(一)
- 修改MySql中数据表和字段的字符集和排序规则
- 345. Reverse Vowels of a String*
- 预处理命令: #if ,#ifdef ,#ifndef
- centsos7 maridb修改过密码之后执行mysql进不去
- Android 沉浸式状态栏之---纯色状态栏
- Linux下的find命令详解
- 原生app中webWiew中js与java交互
- DOM高级应用(一)
- hdu5805
- 关于Android 6.0的权限问题这个大坑记录