leetcode 345. Reverse Vowels of a String 解题报告
来源:互联网 发布:王柳雯的淘宝店 编辑:程序博客网 时间:2024/05/16 01:53
原题链接
解题思路
- 首先将元音存储在一个list中,方便判断。(包括大小写)
- 遍历原字符串将里面的元音记录到StringBuilder中,并反转
- 遍历原字符串,将反转后的StringBuilder里的char写入char数组中
- 将char数组转化为String返回
解题代码
public class Solution { public String reverseVowels(String s) { List<Character> list = new ArrayList<Character>(); list.add('a');list.add('o');list.add('e');list.add('i');list.add('u'); list.add('A');list.add('O');list.add('E');list.add('I');list.add('U'); StringBuilder sb = new StringBuilder(); char[] cs= s.toCharArray(); for(int i=0;i<cs.length;i++){ if(list.contains(cs[i])){ sb.append(cs[i]); } } sb.reverse(); int k = 0; for(int i=0;i<cs.length;i++){ if(list.contains(cs[i])){ cs[i] = sb.charAt(k++); } } return new String(cs); }}
0 0
- [leetcode] 345. Reverse Vowels of a String 解题报告
- 【LeetCode】345. Reverse Vowels of a String 解题报告
- leetcode 345. Reverse Vowels of a String 解题报告
- LeetCode 345. Reverse Vowels of a String 解题报告
- [Leetcode] 345. Reverse Vowels of a String 解题报告
- 【LeetCode】Reverse Vowels of a String 解题报告
- Leetcode #345. Reverse Vowels of a String 逆转元音字母 解题报告
- LeetCode 345. Reverse Vowels of a String
- leetcode-345. Reverse Vowels of a String
- #leetcode#345. Reverse Vowels of a String
- [leetcode] 345. Reverse Vowels of a String
- Leetcode:345. Reverse Vowels of a String
- LeetCode *** 345. Reverse Vowels of a String
- LeetCode.345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- Leetcode 345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- 345.[LeetCode]Reverse Vowels of a String
- SSH框架总结
- 查询到的关于PDO的一点内容
- Rabbitmq+SimpleAmqpClient--之vs2010编译
- spring的事务管理有几种方式实现,如何实现
- 计算机学习速成法
- leetcode 345. Reverse Vowels of a String 解题报告
- 文章标题
- 图像局部特征(三)--FAST角点检测子
- 51nod 1417 天堂里的游戏
- POJ 2251 简单BFS
- Linux学习之CentOS(三)----CentOS 7 下的软件安装方法及策略
- 从0开始学习GitHub系列之「Git 速成」
- 学术论文英文催稿模板
- 剑指offer题解 孩子们的游戏(圆圈中最后剩下的数)