345. reverse vowels of a string

Write a function that takes a string as input and reverse only the vowels of a string.

Example 1:

1
2
Input: "hello"
Output: "holle"

Example 2:

1
2
Input: "leetcode"
Output: "leotcede"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class  {
public String reverseVowels(String s) {
if (s == null || s.length() < 2) {
return s;
}
String vowels = "AaEeIiOoUu";
Arrays.asList(vowels);
char[] ch = s.toCharArray();
int start = 0;
int end = ch.length - 1;
while (start < end) {
while (start < end && !vowels.contains(ch[start] + "")) {
start ++;
}
while (start < end && !vowels.contains(ch[end] + "")) {
end --;
}
char temp = ch[start];
ch[start] = ch[end];
ch[end] = temp;
start ++;
end --;

}
return new String(ch);
}
}