leetcode [#344] | GCidea's blog
目录

题目
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”.Note:
The vowels does not include the letter “y”.
解决方案
1 | public class Solution { |
注意事项
- 元音字母为a,e,i,o,u,同时要考虑到大写。
- 第一次遍历找到所有元音字母并按顺序保存到一个builderVowel中。第二次遍历,如果当前为不是原因,直接添加到结果builder中,如果当前位是元音字母,则从builderVowel尾部取出一个字符添加到builder中。