1
class Solution {
2
public String reverseVowels(String s) {
3
Set<Character> set = new HashSet<>();
4
set.add('a');
5
set.add('e');
6
set.add('i');
7
set.add('o');
8
set.add('u');
9
set.add('A');
10
set.add('E');
11
set.add('I');
12
set.add('O');
13
set.add('U');
14

15
StringBuilder str = new StringBuilder(s);
16
int left = 0, right = str.length() - 1;
17
while (left < right) {
18
if (!set.contains(str.charAt(left))) {
19
left++;
20
}
21
if (!set.contains(str.charAt(right))) {
22
right--;
23
}
24
if (set.contains(str.charAt(left)) && set.contains(s.charAt(right))) {
25
char temp = str.charAt(left);
26
str.setCharAt(left++, str.charAt(right));
27
str.setCharAt(right--, temp);
28
}
29
}
30
return str.toString();
31
}
32
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0