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

    推荐阅读