Leetcode|Leetcode - Reverse Vowels of a String
【Leetcode|Leetcode - Reverse Vowels of a String】My code:
public class Solution {
public String reverseVowels(String s) {
if (s == null || s.length() == 0) {
return s;
}char[] arr = s.toCharArray();
int i = 0;
int j = arr.length - 1;
while (i < j) {
while (i < j && !isVowel(s.charAt(i))) {
i++;
}
while (j > i && !isVowel(s.charAt(j))) {
j--;
}
if (i >= j) {
break;
}
else {
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}return new String(arr);
}private boolean isVowel(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
return true;
}
else if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
return true;
}
else {
return false;
}
}
}
简单题。
vowel 元音字母
aeiou
AEIOU
大写字母也需要考虑。
Anyway, Good luck, Richardo! -- 08/27/2016
推荐阅读
- leetcode|leetcode 188 题
- LeetCode刷题|recording:24. 两两交换链表中的节点
- LeetCode刷题|recording:59.螺旋矩阵II
- leetcode|leetcode 437. Path Sum III 路径总和 III(中等)
- 92.|92. Reverse Linked List II
- leetcode|LeetCode 1048. Longest String Chain
- leetcode 104. Maximum Depth of Binary Tree 二叉树的最大深度(简单)
- LeetCode|LeetCode_二分搜索_中等_540.有序数组中的单一元素
- LeetCode|LeetCode_栈_中等_735.行星碰撞
- LeetCode|LeetCode_双指针_中等_611.有效三角形的个数