package com.fishercoder.solutions;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * 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:
 Given s = "hello", return "holle".

 Example 2:
 Given s = "leetcode", return "leotcede".

 Note:
 The vowels does not include the letter "y".*/
public class _345 {
	public static class Solution1 {
		public String reverseVowels(String s) {
			StringBuilder sb = new StringBuilder(s);
			Set<Character> vowels = new HashSet(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
			//use two pointers approach would be the fastest
			int i = 0;
			int j = s.length() - 1;
			while (i < j) {
				char left = s.charAt(i);
				char right = s.charAt(j);
				while (i < j && !vowels.contains(left)) {
					i++;
					left = s.charAt(i);
				}
				while (i < j && !vowels.contains(right)) {
					j--;
					right = s.charAt(j);
				}
				char temp = left;
				sb.setCharAt(i, right);
				sb.setCharAt(j, temp);
				i++;
				j--;
			}
			return sb.toString();
		}
	}
}

@@ -113,312 +113,8 @@
 %0D%0A%0D%0A
-/**%0D%0A * 345. Reverse Vowels of a String%0D%0A *%0D%0A * Write a function that takes a string as input and reverse only the vowels of a string.%0D%0A%0D%0A Example 1:%0D%0A Given s = %22hello%22, return %22holle%22.%0D%0A%0D%0A Example 2:%0D%0A Given s = %22leetcode%22, return %22leotcede%22.%0D%0A%0D%0A Note:%0D%0A The vowels does not include the letter %22y%22.*/%0D%0A
 publ
@@ -130,17 +130,20 @@
 _345 %7B%0D%0A
-%09
+    
 public s
@@ -167,18 +167,24 @@
 ion1 %7B%0D%0A
-%09%09
+        
 public S
@@ -216,19 +216,28 @@
 g s) %7B%0D%0A
-%09%09%09
+            
 StringBu
@@ -270,19 +270,28 @@
 er(s);%0D%0A
-%09%09%09
+            
 Set%3CChar
@@ -385,19 +385,28 @@
 'U'));%0D%0A
-%09%09%09
+            
 //use tw
@@ -451,26 +451,44 @@
 st%0D%0A
-%09%09%09int i = 0;%0D%0A%09%09%09
+            int i = 0;%0D%0A            
 int 
@@ -508,19 +508,28 @@
 ) - 1;%0D%0A
-%09%09%09
+            
 while (i
@@ -537,20 +537,32 @@
 %3C j) %7B%0D%0A
-%09%09%09%09
+                
 char lef
@@ -579,20 +579,32 @@
 At(i);%0D%0A
-%09%09%09%09
+                
 char rig
@@ -622,20 +622,32 @@
 At(j);%0D%0A
-%09%09%09%09
+                
 while (i
@@ -685,149 +685,257 @@
  %7B%0D%0A
-%09%09%09%09%09i++;%0D%0A%09%09%09%09%09left = s.charAt(i);%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%09while (i %3C j && !vowels.contains(right)) %7B%0D%0A%09%09%09%09%09j--;%0D%0A%09%09%09%09%09right = s.charAt(j);%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%09
+                    i++;%0D%0A                    left = s.charAt(i);%0D%0A                %7D%0D%0A                while (i %3C j && !vowels.contains(right)) %7B%0D%0A                    j--;%0D%0A                    right = s.charAt(j);%0D%0A                %7D%0D%0A                
 char
@@ -949,20 +949,32 @@
  left;%0D%0A
-%09%09%09%09
+                
 sb.setCh
@@ -990,20 +990,32 @@
 ight);%0D%0A
-%09%09%09%09
+                
 sb.setCh
@@ -1034,37 +1034,79 @@
 );%0D%0A
-%09%09%09%09i++;%0D%0A%09%09%09%09j--;%0D%0A%09%09%09%7D%0D%0A%09%09%09
+                i++;%0D%0A                j--;%0D%0A            %7D%0D%0A            
 retu
@@ -1128,14 +1128,23 @@
 );%0D%0A
-%09%09%7D%0D%0A%09
+        %7D%0D%0A    
 %7D%0D%0A%7D

refactor 345