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".

Note:
The vowels does not include the letter "y".

public String reverseVowels(String s) {
ArrayList<Character> vowList = new ArrayList<Character>();
vowList.add('a');
vowList.add('e');
vowList.add('i');
vowList.add('o');
vowList.add('u');
vowList.add('A');
vowList.add('E');
vowList.add('I');
vowList.add('O');
vowList.add('U'); char[] arr = s.toCharArray();//将字符串转换为arraylist数据 int i=0;
int j=s.length()-1; while(i<j){
if(!vowList.contains(arr[i])){
i++;
continue;
} if(!vowList.contains(arr[j])){
j--;
continue;
} char t = arr[i];
arr[i]=arr[j];
arr[j]=t; i++;
j--;
} return new String(arr);
}

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

  1. 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 ...

  2. Leetcode 345 Reverse Vowels of a String 字符串处理

    题意:倒置字符串中的元音字母. 用两个下标分别指向前后两个相对的元音字母,然后交换. 注意:元音字母是aeiouAEIOU. class Solution { public: bool isVowel ...

  3. LeetCode 345. Reverse Vowels of a String(双指针)

    题意:给定一个字符串,反转字符串中的元音字母. 例如: Input: "leetcode" Output: "leotcede" 法一:双指针 class So ...

  4. Leetcode 345 Reverse Vowels in a String

    两个for 第一个for将每一个元音依次存放进一个char数组 第二个for,每检测到元音,就从char数尾部开始,依次赋值 如何检测元音呢?当然写一个冗长的if(),不过我们有更好的选择 hashs ...

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

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

  6. 345. Reverse Vowels of a String - LeetCode

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

  7. 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 ...

  8. 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 ...

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

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

随机推荐

  1. Python学习笔记(1)

    001 #通过bat命令运行pyhon py文件,并将结果输出到txt文件.# D:\ResearchContent\Exercise_Programm\Start\Start.py>C:\Us ...

  2. Collection集合的功能及总结

    Collection集合是集合顶层接口,不能实例化 功能 1.添加功能 boolean add(Object obj):添加一个元素 boolean addAll(Collection c):添加一个 ...

  3. JavaScript中的静态成员

    静态:共享 一.公有静态成员(作为函数的属性即可): var Gadget = function(price) { this.price = price; } Gadget.isShiny = fun ...

  4. nginx_mysql_redis配置

    #Nginx所用用户和组,window下不指定 #user nobody; #工作的子进程数量(通常等于CPU数量或者2倍于CPU) worker_processes 2; #错误日志存放路径 #er ...

  5. Python

    语法 #!/usr/bin/python 注释:# 编码:# -*- coding: UTF-8 -*- 缩进 运算符 算数运算符 + 加 - 两个对象相加 a + b 输出结果 30 - 减 - 得 ...

  6. zend studio面板功能

    不小心把zend界面右边的显示类中各个方法的窗口关掉了,如何打开呢: 法一:点击Windows菜单,选择show view项,选择outline即可: 法二:点击Windows菜单,选择Reset P ...

  7. 修改context 和 enforce?

    http://jingyan.baidu.com/article/8ebacdf0cce84849f75cd57b.html 可以彻底的 关闭 selinux, selinux的配置文件 在 /etc ...

  8. php中引用&的真正理解-变量引用、函数引用、对象引用

    php的引用(就是在变量或者函数.对象等前面加上&符号) //最重要就是 删除引用的变量 ,只是引用的变量访问不了,但是内容并没有销毁 在PHP 中引用的意思是:不同的名字访问同一个变量内容. ...

  9. Redis实战阅读笔记——第二章

    在性能的要求下,如何获取重构之前的构件

  10. 等价类划分方法的应用(jsp)

    [问题描述] 在三个文本框中输入字符串,要求均为1到6个英文字符或数字,按submit提交. [划分等价类] 条件1: 字符合法; 条件2: 输入1长度合法; 条件3: 输入2长度合法: 条件4: 输 ...