@@ -0,0 +1,1075 @@
+package easy;%0D%0A%0D%0Aimport java.util.HashSet;%0D%0Aimport java.util.Set;%0D%0A%0D%0Apublic class ReverseVowelsOfAString %7B%0D%0A%09public String reverseVowels(String s) %7B%0D%0A%09%09StringBuilder sb = new StringBuilder(s);%0D%0A%09%09Set%3CCharacter%3E vowels = new HashSet();%0D%0A%09%09vowels.add('a');%0D%0A%09%09vowels.add('e');%0D%0A%09%09vowels.add('i');%0D%0A%09%09vowels.add('o');%0D%0A%09%09vowels.add('u');%0D%0A%09%09vowels.add('A');%0D%0A%09%09vowels.add('E');%0D%0A%09%09vowels.add('I');%0D%0A%09%09vowels.add('O');%0D%0A%09%09vowels.add('U');%0D%0A%09%09//use two pointers approach would be the fastest%0D%0A%09%09int i = 0, j = s.length()-1;%0D%0A%09%09while (i %3C j)%7B%0D%0A%09%09%09char left = s.charAt(i), right = s.charAt(j);%0D%0A%09%09%09while(i %3C j && !vowels.contains(left))%7B%0D%0A%09%09%09%09i++;%0D%0A%09%09%09%09left = s.charAt(i);%0D%0A%09%09%09%7D%0D%0A%09%09%09while(i %3C j && !vowels.contains(right))%7B%0D%0A%09%09%09%09j--;%0D%0A%09%09%09%09right = s.charAt(j);%0D%0A%09%09%09%7D%0D%0A%09%09%09char temp = left;%0D%0A%09%09%09sb.setCharAt(i, right);%0D%0A%09%09%09sb.setCharAt(j, temp);%0D%0A%09%09%09i++; j--;%0D%0A%09%09%7D%0D%0A%09%09return sb.toString();%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void main(String...strings)%7B%0D%0A%09%09ReverseVowelsOfAString test = new ReverseVowelsOfAString();%0D%0A%09%09String s = %22leetcode%22;%0D%0A%09%09System.out.println(test.reverseVowels(s));%0D%0A%09%7D%0D%0A%7D%0D%0A

reverse vowels of a string