My Java Solution


  • 0
    public String reverseVowels(String s) {
            char [] ss = s.toCharArray();
            String vowels = "aeiouAEIOU";
            int left = 0;
            int right = ss.length-1;
            while(true){
                while(left<right){
                    if(!vowels.contains(ss[left]+""))
                        left++;
                    else
                        break;
                }
                while(left<right){
                    if(!vowels.contains(ss[right]+""))
                        right--;
                    else
                        break;
                }
                if(left<right){
                    char tmp = ss[left];
                    ss[left] = ss[right];
                    ss[right] = tmp;
                    left++;
                    right--;
                }else{
                    break;
                }
            }
            return new String(ss);
        }
    

Log in to reply
 

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