#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

05-11 18:12