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".
Subscribe to see which companies asked this question
1 Public classSolution {2 Publicstring Reversevowels (string s) {3 if(NULL= = s)returns;4 Char[] tmp =S.tochararray ();5stack<character> stack =NewStack<character>();6 for(inti = 0; i<tmp.length; i++){7 if(Isvowels (Tmp[i])) {8 Stack.push (Tmp[i]);9 }Ten } One for(inti = 0; i<tmp.length; i++){ A if(Isvowels (Tmp[i])) { -Tmp[i] =Stack.pop (); - } the } -String res =NewString (TMP); - returnRes; - } + - Public BooleanIsvowels (Charc) { + if(c = = ' A ' | | c = = ' E ' | | c = = ' I ' | | c = = ' O ' | | c = = ' A ' | | c = = ' E ' | | = c = ' I ' | | ){ A return true; at } - return false; -}
345. Reverse vowels of a String Java Solutions