Leetcode String Handling problem Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.