Reverse Vowels of a String
Question
Write a function that takes a string as input and reverse only the vowels of a string.
Example:
Given s = "hello", return "holle".
Given s = "leetcode", return "leotcede".
Hint
The vowels does not include the letter "y".
Answer
solution:
Knowledge:
一开始考虑这个问题的时候,我在思考空间上考虑多一个列表保存元音,然后利用一个新的字典保存enumerate找到的元音,但是在互换位置的时候,我遇到了困惑。原来这是一道双指针问题——首尾靠近。我自己在想思考时间部分中考虑到了首尾互相靠近,遇到了合适值再对换,但是不知道代码怎么编写。这说明我需要总结这方面得知识。
Last updated
Was this helpful?