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. 【技巧】为ComboBox添加自动提示

    一.需求来源 最近有个项目用到了ComboBox控件,在演示的时候,要对Word文档中选中部分添加符合DocBook标准的标签,这些标签是DocBook中元素的集合,数据量不多,大概170多个吧,但是 ...

  2. 个人作业——week2

    一.发现的功能性bug 1.这个手机客户端的拍照翻译功能虽然能够正确的识别图像,但是不能有效的识别出图像中的文字,给出的提示总是图像识别成功,没有识别到文字,导致这个功能几乎无法使用. 因为刚下载这个 ...

  3. 创建Mat对象的几种方法

    1.Mat的构造函数 Mat M(行数,列数,数据类型,通道数) eg:M(2,2, CV_8UC3, Scalar(0,0,255)). 2.利用Mat的Create()函数.Mat M; M.cr ...

  4. checkbox的全选与反选

    最近在做一个项目,其中一个功能就是多选框的全选与反选.感觉很简单的小功能,一下子想不起来怎么实现了,很是耽误时间.我在想,我有必要整理下自己的一些小demo了,也方便以后再使用的时候能快速的完成功能. ...

  5. 前端React开发入门笔记

    什么是React React是一个JavaScript库,是由FaceBook和Instagram开发的,主要用于用户创建图形化界面. Hello world <!DOCTYPE html> ...

  6. Apache Shiro 学习记录4

    今天看了教程的第三章...是关于授权的......和以前一样.....自己也研究了下....我觉得看那篇教程怎么说呢.....总体上是为数不多的精品教程了吧....但是有些地方确实是讲的太少了.... ...

  7. TeamViewer 12.0.71503 Patch By.Sound

    TeamViewer - the All-In-One Software for Remote Support and Online Meetings - Remote control any com ...

  8. 前端应当了解的Web缓存知识

    缓存优点 通常所说的Web缓存指的是可以自动保存常见http请求副本的http设备.对于前端开发者来说,浏览器充当了重要角色.除此外常见的还有各种各样的代理服务器也可以做缓存.当Web请求到达缓存时, ...

  9. python 解压 压缩包

    转 http://m.blog.csdn.net/blog/wice110956/26597179# 这里讨论使用Python解压如下五种压缩文件: .gz .tar  .tgz .zip .rar ...

  10. jQuery插件中的this指的是什么

    在jQuery插件的范围里, this关键字代表了这个插件将要执行的jQuery对象, 但是在其他包含callback的jQuery函数中,this关键字代表了原生的DOM元素.这常常会导致开发者误将 ...