Leetcode 345.反转字符串中的元音字母

345. 反转字符串中的元音字母

编写一个函数,以字符串作为输入,反转该字符串中的元音字母。

示例 1:

输入: "hello"

输出: "holle"

示例 2:

输入: "leetcode"

输出: "leotcede"

说明:
元音字母不包含字母"y"

 

 1 public class Solution{
 2     public String reverseVowels(String s){
 3         String voewls="aeiouAEIOU";
 4         char[] a=s.toCharArray();
 5         int i=0;
 6         int j=a.length-i-1;
 7         while(i<j){
 8             while(i<j&&!voewls.contains(a[i]+"")){
 9                 i++;
10             }
11             while(i<j&&!voewls.contains(a[j]+"")){
12                 j--;
13             }
14             if(i<j){
15                 char c=a[i];
16                 a[i++]=a[j];
17                 a[j--]=c;
18             }
19         }
20         return new String(a);
21     }
22 }
原文地址:https://www.cnblogs.com/kexinxin/p/10235278.html