345. Reverse Vowels of a String
来源:互联网 发布:手机棋牌源码 编辑:程序博客网 时间:2024/06/05 09:01
Reverse Vowels of a String
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”.
将字符串里的元音字符交换位置.
public class Solution { public String reverseVowels(String s) { char[] str = s.toCharArray(); Set<Character> set = new HashSet<>(); set.add('a'); set.add('o'); set.add('e'); set.add('i'); set.add('u'); set.add('A'); set.add('O'); set.add('E'); set.add('I'); set.add('U'); int start = 0; int end = str.length - 1; while (true) { while (start < end && !set.contains(str[start])) start++; while (start < end && !set.contains(str[end])) end--; if (start >= end) { return new String(str); } else { char temp = str[start]; str[start] = str[end]; str[end] = temp; start++; end--; } } }}
0 0
- String:345. Reverse Vowels of a String
- 345. Reverse Vowels of a String 【E】
- LeetCode 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- leetcode-345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- #leetcode#345. Reverse Vowels of a String
- [leetcode] 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- Leetcode:345. Reverse Vowels of a String
- LeetCode *** 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- LeetCode.345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- Oracle 常用命令
- HDU 1003 Max Sum
- zoj 3430 AC自动机
- torch7学习笔记1——itorch_notebook与lua编译的安装
- RTSP协议
- 345. Reverse Vowels of a String
- 《LeetBook》leetcode题解(20):Valid Parentheses[E]——栈解决括号匹配问题
- AFNetworking 2.x 的SSL身份认证
- MySql乱码解决
- COM口 大于9 连接不上问题总结
- 关于Mac下的Android Studio无法显示类的相关文档和关联源代码的问题
- 从头认识多线程-2.3 synchronized持有对象锁与类锁的不同点
- 简单聊一下Android 6.0的运行时权限
- fedora 一命令安装 maven