leetcode345: Reverse Vowels of a String
来源:互联网 发布:mysql时间函数 编辑:程序博客网 时间:2024/06/08 11:33
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".
注意:不能直接返回(数组名).toString 此时会返回地址名
public String reverseVowels(String s) {char[] c = s.toCharArray();int i = 0;int j = c.length - 1;char ch;ArrayList list = new ArrayList();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');while (i < j) {System.out.print(i);System.out.print(j);System.out.println();if (!list.contains(c[i]))i++;if (!list.contains(c[j]))j--;if (list.contains(c[i]) && list.contains(c[j])) {ch = c[i];c[i] = c[j];c[j] = ch;i++;j--;}}return new String(c);}
0 0
- LeetCode345—Reverse Vowels of a String
- LeetCode345. Reverse Vowels of a String
- Leetcode345. Reverse Vowels of a String
- leetcode345: Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- String:345. Reverse Vowels of a String
- fully_connected_feed代码说明
- Android加载大图
- u-boot移植
- Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
- UIImage和NSData相互转换
- leetcode345: Reverse Vowels of a String
- hrbust1530 pie
- 组合数(dfs)
- Ubuntu 14.04编译安装hadoop 2.7.3
- Android Framework学习(六)之RefBase,SP,WP
- JAVA基础总结知识
- 抽象类、接口(包括Java8新特性)
- 界面让table居中的办法
- 【每日一问】数组 new问题