Reverse Vowels of a String
https://leetcode.com/problems/reverse-vowels-of-a-string/description/
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".
Thoughts
题目要求把元音前后对调,因此需要两个指针分别指向需要对调的元素。
Code
Analysis
时间复杂度O(n).
Last updated
Was this helpful?