/* * Two Pointers */ classSolution { public String reverseVowels(String s) { char[] arr = s.toCharArray(); Stringvowels="aeiouAEIOU"; // Use two pointers intleft=0; intright= arr.length - 1; while (left < right){ // Move left pointer until it points to a vowel while (left < right && vowels.indexOf(arr[left]) == -1){ left++; } // Move right pointer until it points to a vowel while (left < right && vowels.indexOf(arr[right]) == -1){ right--; } // Swap the vowels chartemp= arr[left]; arr[left] = arr[right]; arr[right] = temp; // Update idx left++; right--; } returnnewString(arr); } }