Reverse Vowels of a String
2016-07-24 03:53
204 查看
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".
vowels:元音aeiou
解法:two pointers
Example 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
Note:
The vowels does not include the letter "y".
vowels:元音aeiou
解法:two pointers
public class Solution { public String reverseVowels(String s) { String vowel = "aeiouAEIOU"; int start = 0; int end = s.length()-1; char[] chars = s.toCharArray(); while(start<end) { while(start<end&&!vowel.contains(chars[start]+"")) { start++; } while(start<end&&!vowel.contains(chars[end]+"")) { end--; } char temp = chars[start]; chars[start]=chars[end]; chars[end]=temp; start++; end--; } return String.valueOf(chars); } }
chars[end]+"" 这里加上“”很重要,不然会出以下错误:
error: incompatible types: char cannot be converted to CharSequence
相关文章推荐
- 用vbs 将有序文件转换为有序文件
- HTML5网页新风格总结(与html4对比)
- 一个小玩意引起的反思
- 基于内容的推荐(第二周)
- jquery中each的三种遍历方法
- 开始使用Gulp
- Meeting Rooms
- Meeting Rooms
- 网站性能测试工具ab学习
- 打印一个N*N的方阵,N为每边字符的个数,要求最外层为“X”,第二层为“Y”,从第三层起每层依次打印数字0,1,2,3,...
- TensorFlow安装教程与Android Camera Demo示例(Ubuntu Trusty 14.04 LTS)
- 海贼王 手游 自己搭建自娱自乐
- 写在最开始,写给自己
- 协同过滤推荐(第1周)
- 关于ubuntu上android studio的theme editor 不显示的问题
- 215. Kth Largest Element in an Array
- Codeforces Round #324 (Div. 2)ABC
- SoC keywords
- Juqery 复选框全选/全部取消
- Linux C++ 实现时间轮 优化超时检测机制