345.反转字符串中的元音字母 class Solution { public String reverseVowels(String s) { int len = s.length(); if(len < 2){ return s; } char[] charArray = s.toCharArray(); int left = 0,right = len - 1; while(true){ while(left < len && checkVowels(charArray[left])){ left++; } while(right >= 0 && checkVowels(charArray[right])){ right--; } if(left < right){ swap(charArray,left,right); left++; right--; }else{ break; } } return new String(charArray); } private void swap(char[] chars,int n ,int m){ char tmp = chars[n]; chars[n] = chars[m]; chars[m] = tmp; } private boolean checkVowels(char c){ return c!='a' && c!='e' && c!='i' && c!='o' && c!='u' && c!='A' && c!='E'&&c!='O'&&c!='I'&&c!='U'; } }