Basic Java solution, easy to understand


  • 0

    '''

    public String reverseVowels(String s) {
    int left=0;
    int right=s.length()-1;
    char[] c = s.toCharArray();
    while(left<right)
    {
    while(left<right&&!(c[left]=='a'||c[left]=='e'||c[left]=='i'||c[left]=='o'||c[left]=='u'||
    c[left]=='A'||c[left]=='E'||c[left]=='I'||c[left]=='O'||c[left]=='U'))

            {
                left++;
    
            }
            
            while(left<right&&!(c[right]=='a'||c[right]=='e'||c[right]=='i'||c[right]=='o'||c[right]=='u'||
            c[right]=='A'||c[right]=='E'||c[right]=='I'||c[right]=='O'||c[right]=='U'))
            {
                 right--;
            }
            char temp= c[left];
            c[left]=c[right];
            c[right]=temp;
            left++;
            right--;
        }
        String b = new String(c);
        return b;
        
    }
    

    '''


Log in to reply
 

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