Java Solution


  • 0
    P
    public String reverseVowels(String s) {
            if(s == null || s.length()==0) return s;  
            
            String a="";
            for(char c: s.toCharArray()){
                if(c =='a' || c=='e' || c=='i' || c== 'o' || c=='u'|| c=='A' || c=='E' || c=='I' || c=='O'|| c=='U')
                    a=a+c;
            }
             
            int l=a.length();
           char[] chars = s.toCharArray();
            for(int i=0;i<chars.length;i++){
                char c= chars[i];
                 if(c =='a' || c=='e' || c=='i' || c== 'o' || c=='u'|| c=='A' || c=='E' || c=='I' || c=='O'|| c=='U'){
                     
                     chars[i] = a.charAt(l-1);
                     l--;
                 }                      
            }
                    
            return new String(chars);
            
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.