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. pandas read table

    http://pandas.pydata.org/pandas-docs/stable/10min.html import pandas as pd res = pd.read_table(" ...

  2. Windows bat脚本学习(1)

    基础 首先所有命令在cmd命令行中都能找到说明: 例如 想知道type用法 输入type /? 其他命令都一样 type [drive:][path] filename 显示文本文件内容 虽然有点鸡肋 ...

  3. Python Day12

    MySQL 数据库介绍 什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库, 每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制所保存的数据. 我们 ...

  4. Android开发环境搭建

    导读: 学习Android开发第一步就是搭建Android开发环境. 1.安装JDK JDK(Java SE Development Kit)是Java的开发工具集.SE表示标准版. JRE(Java ...

  5. nginx本地转发

    在conf文件下找到nginx.conf配置文件:添加如下代码:

  6. Linux 基本命令

    修改环境变量 vim ~/.bashrc 保存退出,输入以下命令使之立即生效 source ~/.bashrc /etc/profile:在登录时,操作系统定制用户环境时使用的第一个文件,此文件为系统 ...

  7. Spring学习记录1--@Transactional Propagation

    起因 学习Spring的时候就知道aop有一个应用是声明式注解..反正往Service上一丢@Transactional就完事了..不用自己去开启hibernate的session,很简单. 但是@T ...

  8. ThinkPHP的URL访问

    url访问 http://www.kancloud.cn/manual/thinkphp5/118012 ThinkPHP5.0在没有启用路由的情况下典型的URL访问规则是: http://serve ...

  9. vtkTransform实例 1

    1. 4*4矩阵类vtkMatrix4x4 接口函数:void SetElement(int i, int j, double value),i行.j列的值为value #ifndef INITIAL ...

  10. kafka(logstash) + elasticsearch 构建日志分析处理系统

    第一版:logstash + es 第二版:kafka 替换 logstash的方案