Write a function that takes a string as input and reverse only the vowels of a string.

Example 1:
Given s = "hello", return "holle".

Example 2:
Given s = "leetcode", return "leotcede".

代码如下:

 public class Solution {
public String reverseVowels(String s) {
ArrayList<Character> list=new ArrayList<>();
char[] ss=s.toCharArray();
list.add('a');
list.add('e');
list.add('i');
list.add('o');
list.add('u');
list.add('A');
list.add('E');
list.add('I');
list.add('O');
list.add('U');
int i=0,j=s.length()-1;
while(i<j)
{
while(!list.contains(ss[i])&&i<j)
i++;
while(!list.contains(ss[j])&&i<j)
j--; char c=ss[i];
ss[i]=ss[j];
ss[j]=c; i++;j--;
}
s=String.valueOf(ss);
return s;
}
}

345. Reverse Vowels of a String的更多相关文章

  1. 345. Reverse Vowels of a String(C++)

    345. Reverse Vowels of a String Write a function that takes a string as input and reverse only the v ...

  2. 【leetcode】345. Reverse Vowels of a String

    problem 345. Reverse Vowels of a String class Solution { public: string reverseVowels(string s) { , ...

  3. 345. Reverse Vowels of a String【easy】

    345. Reverse Vowels of a String[easy] Write a function that takes a string as input and reverse only ...

  4. 345. Reverse Vowels of a String - LeetCode

    Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...

  5. Python [Leetcode 345]Reverse Vowels of a String

    题目描述: Write a function that takes a string as input and reverse only the vowels of a string. Example ...

  6. 【一天一道LeetCode】#345. Reverse Vowels of a String

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

  7. 345. Reverse Vowels of a String【Easy】【双指针-反转字符串中的元音字符】

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...

  8. 345. Reverse Vowels of a String翻转字符串中的元音字母

    [抄题]: Write a function that takes a string as input and reverse only the vowels of a string. Example ...

  9. [LC] 345. Reverse Vowels of a String

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...

随机推荐

  1. 常见JS(JavaScript)冲突解决方法

    1.一般JS冲突解决办法 a.最容易出现的就是js的命名冲突 ①.变量名冲突 变量有全局变量和局部变量当全局变量变量和局部变量名称一致时,就会js冲突,由于变量传递数值或地址不同就会产生JavaScr ...

  2. Oracle练习题(1~19)

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. 2. 查询教师所有的单位即不重复的Depart列. 3. 查询Student表的所有记录. 4. 查询Score表中成绩在 ...

  3. POJ 1503 Integer Inquiry 大数 难度:0

    题目链接:http://poj.org/problem?id=1503 import java.io.*; import java.math.BigInteger; import java.util. ...

  4. HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)

    题意:构造出n个数 这n个数取值范围0-L,这n个数中存在取一些数之和等于k,则这样称为一种方法.给定n,k,L,求方案数. 思路:装压 每位 第1为表示这种方案能不能构成1(1表示能0表示不能)   ...

  5. wp8.1 Study13:在WP8.1中分享文件和数据

    绪论:不同于windows, 在wp8.1中,如果不止一个程序可以接受其Uri或者文件,shell会提供一个界面让用户选择用哪个程序.而在windows中,用户可以在设置那里设置各种文件和Uri的默认 ...

  6. SQL with PL/SQL

    DDL commands --> create user / table / view / sequence alter DML --> data manipulation languag ...

  7. MSP430G2553之timerA产生PWM

    总结:选SMCLK(可以测出来)         若选ACLK,经示波器PWM时有时无 举例一: #include <MSP430G2553.h> #define CPU_F ((doub ...

  8. poj3126 筛素数+bfs

    //Accepted 212 KB 16 ms //筛素数+bfs #include <cstdio> #include <cstring> #include <iost ...

  9. JS 原型继承的几种方法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. hdu 2085

    PS:递推题..  a[n]=a[n-1]*3+2*b[n-1]  b[n]=a[n-1]+b[n-1] 代码: #include "stdio.h" ]; ]; int main ...