【leetcode】(Python)Reverse Vowels of a String实现字符串内元字符倒序
2016-04-24 13:38
731 查看
leetcode:(Python)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".
其实是leetcode上面的一道题目
没有python版本的故来抛砖,经提交可通过
class Solution(object):
def reverseVowels(self, s):
string=list(s)
j=0
n=0
m=[]
k=[]
for i in s:
if i=='a'or i=='e' or i=='i' or i=='o' or i=='u' or i=='A'or i=='E' or i=='I' or i=='O' or i=='U':
m.append(j)
j=j+1
if len(m)>1:
for i in m:
k.append(s[i])
k.reverse()
for i in m:
string[i]=k
n=n+1
string=''.join(string)
return string
(需要注意的是题意为将“所有”元音字母倒序,并且原因字母要考虑到大小写)
Example 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
其实是leetcode上面的一道题目
没有python版本的故来抛砖,经提交可通过
class Solution(object):
def reverseVowels(self, s):
string=list(s)
j=0
n=0
m=[]
k=[]
for i in s:
if i=='a'or i=='e' or i=='i' or i=='o' or i=='u' or i=='A'or i=='E' or i=='I' or i=='O' or i=='U':
m.append(j)
j=j+1
if len(m)>1:
for i in m:
k.append(s[i])
k.reverse()
for i in m:
string[i]=k
n=n+1
string=''.join(string)
return string
相关文章推荐
- python函数(一)
- python的多重继承
- Python, MySQLdb 编码问题 UnicodeEncodeError:'latin-1' codec can't encode character ...
- 菜鸟学python(11)list列表基本操作
- python range和xrange
- ipython and bpython
- windows环境下在python中用opencv
- python常见问题与解答
- 基础知识(十六)Opencv、python、ubuntu
- scikit-learn学习之K最近邻算法(KNN)
- python random()函数
- python编解码的那些事儿
- Python学习笔记09
- 力推一种python开发环境-Anaconda2
- 装饰器 ---- python
- 用Python制作markdown编辑器
- 步入python与Opencv
- Python学习笔记08
- python 生成qrcode二维码
- python基础一