344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "Hello", Return "Olleh".
Subscribe to see which companies asked this question
Public classSolution { Publicstring reversestring (string s) {if(s==NULL) return""; CharC[] =S.tochararray (); intLen =s.length (); intI=0; intJ=len-1; while(i<j) { CharTMP =C[i]; C[i]=C[j]; C[J]=tmp; ++i; --J; } return NewString (c); }}345. Reverse vowels of a StringTotal Accepted: 4116 all submissions: 11368 Difficulty: Easy
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
Flip the string using the partition function of the fast row
Public classSolution { Publicstring Reversevowels (string s) {if(s==NULL){ return""; } Char[] C =S.tochararray (); intleft = 0; intright = C.length-1; while(left<Right ) { while(left<right&&!Isvowel (C[left])) { ++Left ; } while(left<right&&!Isvowel (C[right])) { --Right ; } CharTMP =C[left]; C[left]=C[right]; C[right]=tmp; ++Left ; --Right ; } return NewString (c); }
Checks if a character is a vowel character Public BooleanIsvowel (Charc) { if(c== ' A ' | | c== ' E ' | | c== ' I ' | | c== ' O ' | | c== ' U ' | | c== ' A ' | | c== ' E ' | | c== ' I ' | | c== ' O ' | | c== ' U ') return true; Else return false; }}
Leetcode String Handling problem Java