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. linux 执行php文件

    /opt/php5/bin/php /home/Xcar/tag/interface/tag_api4hbase.php tag_export2file "/tmp/guo.php" ...

  2. Halcon 映射校正例程注释(MapImage)

    *关闭窗口 dev_close_window () dev_close_window () *打开指定大小.颜色背景的窗口 dev_open_window (, , /, /, 'black', Wi ...

  3. C#解析Json(多方法解析Json 一)

    解析:{'id':'4028d80858053bed0158053ef7a50001','sl':0.0,'sfyfz':'0','zwjyzsbh':'1000001600000018'} 1.新建 ...

  4. Javascript arguments详解

    今天我们来看看arguments对象及属性.arguments对象不能显式创建,arguments对象只有函数开始时才可用.函数的 arguments 对象并不是一个数组,访问单个参数的方式与访问数组 ...

  5. Ubuntu14.04安装和配置ROS Indigo(一)

    安装ROS 配置Ubuntu的软件源 配置Ubuntu要求允许接受restricted.universe和multiverse的软件源,可以根据下面的链接配置: https://help.ubuntu ...

  6. C++-前缀和后缀

    1,c++规定后缀形式的++操作符有一个int行的参数,被调用时,编译器自动加一个0作为参数给他 2,前缀返回一个reference,后缀返回一个const对象 /////////////////// ...

  7. highcharts的.net本地导出环境安装记录

    由于项目中highcharts需要内网使用,需要本地搭建导出的环境.下面简述下步骤: 1.下载开源的.net导出文件:https://github.com/imclem/Highcharts-expo ...

  8. 纯JS文本在线HTML编辑器KindEditor

    KindEditor(http://www.kindsoft.net)是一款比较专业,主流,好用的在线HTML编辑器. 它除了可以将文本进行编辑.将Word中的内容复制进来外,本身还可以拖动缩放(右下 ...

  9. 测试bug级别定义

    致命bug:不能完全满足系统要求,系统停止运行,系统的重要部件无法运行,系统崩溃或者挂起等导致系统不能正常运行. 修改优先级为最高,该级别问题需要立即修改. 1.系统崩溃 2.导致程序重启,死机或非法 ...

  10. Introduction to Machine Learning

    Chapter 1 Introduction 1.1 What Is Machine Learning? To solve a problem on a computer, we need an al ...