[LeetCode]--345. Reverse Vowels of a String
来源:互联网 发布:网络打字员是真是假 编辑:程序博客网 时间:2024/05/21 08:36
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”.
public String reverseVowels(String s) { char[] ss = s.toCharArray(); int j = ss.length - 1, i = 0; char temp; while (i < j) { while (i < j && !isVowel(ss[i])) i++; while (i < j && !isVowel(ss[j])) j--; temp = ss[i]; ss[i] = ss[j]; ss[j] = temp; i++; j--; } return String.valueOf(ss); } public boolean isVowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true; if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') return true; return false; }
0 0
- LeetCode 345. Reverse Vowels of a String
- leetcode-345. Reverse Vowels of a String
- #leetcode#345. Reverse Vowels of a String
- [leetcode] 345. Reverse Vowels of a String
- Leetcode:345. Reverse Vowels of a String
- LeetCode *** 345. Reverse Vowels of a String
- LeetCode.345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- Leetcode 345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- 345.[LeetCode]Reverse Vowels of a String
- Leetcode 345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- leetcode 345. Reverse Vowels of a String
- 【leetcode】345. Reverse Vowels of a String
- LeetCode-345.Reverse Vowels of a String
- LeetCode - 345. Reverse Vowels of a String
- [Leetcode]345. Reverse Vowels of a String
- 微信收藏导出到PC端的方法,不要再傻傻的用网页版转换了!
- Java中的static关键字解析
- Mac OSX下使用apt-get命令
- ubuntu上编译安装mysql5.7.x【多次错误之后总结的方法】
- 程序员的分级
- [LeetCode]--345. Reverse Vowels of a String
- Tomcat 8报错 SEVERE: One or more listener failed to start,如何找到更详细的错误信息
- Deep-Learning NotePad1 : Machine-Learning to Deep-Learning
- URAL1222
- hdu 1799 循环多少次?(排列组合,思路)
- Spark程序设计——Scala
- 网络基础
- Python列表
- 137.Clone Graph-克隆图(中等题)