欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

LeetCode:Reverse Vowels of a String

程序员文章站 2022-07-02 15:52:02
total accepted:8150total submissions:23213difficulty:easy write a function that takes a string as i...

total accepted:8150total submissions:23213difficulty: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".

subscribeto see which companies asked this question

hide tags

two pointersstring

hide similar problems

(e) reverse string

 

code:

 

public class solution {
    
    public boolean isvowel(char c) {
        if('a' <= c && c <= 'z') c += 'a'-'a';
        return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
    }
    
    public string reversevowels(string s) {
        int len = s.length();
        char[] chs = s.tochararray();
        int i=0,j=len-1;
        while(i