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. --投资情况统计详情sql

    --投资情况统计详情sqlselect BidRecord.*, RegInfo.UserName,UserInfo.phone,BorrowInfo.Title,BorrowInfo.BorrowC ...

  2. flash as3 socket安全服务网关(socket policy file server)

    关键字: SecurityErrorEvent socket as3 flash有着自己的一套安全处理模式,在socket方面,我这样的菜鸟无法理解他的好处:一句话,不怀好意的人如果想用flash写一 ...

  3. CodeForces 441E(Codeforces Round #252 (Div. 2))

    思路:dp[i][now][mark][len]   i 表示当前第i 次now存的是后8位,mark为第9位为0还是1 len第九位往高位还有几位和第9位相等.  只存后8位的原因:操作只有200次 ...

  4. 常州培训 day1 解题报告

    第一题:(骗分容易,AC难.) 题目大意: 给出一个字符串,找出满足条件A的区间的个数.A:字符A,B,C的出现次数相同. 都出现0次也算,区间的长度可以是0(就是只有一个数).30% |S| ≤ 1 ...

  5. $where $options: 'g','i'

    db.classes.update({"count":{$gt:20}},{$set:{"name":"c4"}},false,false) ...

  6. Spring学习笔记之整合hibernate

    1.web.xml里边要配置好对应的springxml的路径 <context-param> <param-name>contextConfigLocation</par ...

  7. VS2010下配置OCI编程

    OCI是Oracle官方出品的用于C/C++语言连接.操作Oracle数据库的API.在windows操作系统下使用VS等IDE编写.编译C++程序十分方便.简单,不需要使用Makefile.使用OC ...

  8. [网络技术]VPN设置

    1.解决VPN服务器默认路由困扰 现在移动办公已经变得家常便饭,每次外出出差办公需要访问单位的内网服务器时,该怎么办呢?相信很多人都想到了VPN连接!的确,使用VPN连接, 我们可以利用现成的Inte ...

  9. sourcetree使用问题汇总

    1.可优先查阅博文<git 用户手册 1.5.3及后续版本使用>: 2.问题1 Cloning into 'folder'... warning: templates not found ...

  10. 数组的filter方法

    filter()函数用于过滤序列,filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素. eg: var arr=[10,11,12,13,14 ...