Java 10 lines


  • 0
    Y
        public String reverseVowels(String s) {
            char[] chars = s.toCharArray();
            String vowels = "aeiouAEIOU";
            for (int l = 0, h = chars.length - 1; l < h; l++, h--) {
                if (vowels.indexOf(chars[l]) < 0) { h++; continue; }
                if (vowels.indexOf(chars[h]) < 0) { l--; continue; }
                chars[l] ^= chars[h];
                chars[h] ^= chars[l];
                chars[l] ^= chars[h];
            }
            return new String(chars);
        }
    

  • 0

    @yuxiangmusic

    So smooth.


Log in to reply
 

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