Short Java Solution


  • 0
    Y
    public class Solution {
        public String reverseVowels(String s) {
            char[] c = s.toCharArray();
            int i=0, j=s.length()-1;
            String v="aeiouAEIOU";
            char t;
            while(i<j)
            {
                if(!v.contains(Character.toString(c[i])))
                {
                    i++; continue;
                }
                if(!v.contains(Character.toString(c[j])))
                {
                    j--; continue;  
                }
                t=c[i];
                c[i++]=c[j];
                c[j--]=t;
            }
            return String.valueOf(c);
        } 
    }
    

Log in to reply
 

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