Leetcode题解14 345. Reverse Vowels of a String
来源:互联网 发布:ios程序员工资待遇知乎 编辑:程序博客网 时间:2024/04/29 17:18
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 static String reverseVowels(String s) { String ss = "aeiouAEIOU"; StringBuilder sb = new StringBuilder(); StringBuilder result = new StringBuilder(); for (int i = 0; i < s.length(); i++) { if (ss.contains(s.charAt(i) + "")) { sb.append(s.charAt(i)); } } String temp = sb.reverse().toString(); int pos = 0; for (int i = 0; i < s.length(); i++) { if (!ss.contains(s.charAt(i) + "")) { result.append(s.charAt(i)); } else { result.append(temp.charAt(pos)); pos++; } } return result.toString(); }}
0 0
- Leetcode题解14 345. Reverse Vowels of a String
- LeetCode题解:345. Reverse Vowels of a String
- leetcode题解-344. Reverse String && 541. Reverse String II && 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
- 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
- git正确的删除远程仓库的文件并用.gitignore忽略提交此文件
- [mac]MAC实用工具集
- splay
- [ase gitblog]config.yaml配置
- TCP, UDP, Socket. 基础篇
- Leetcode题解14 345. Reverse Vowels of a String
- 发挥GPU强大动力的CG语言
- 1.PHP连接mysql中文乱码问题
- Android View 流程简读 <1>
- C++中 引用&与取地址&的区别
- 1002 Problem B
- android实现ListView字母排序并调整字母位置
- 由PYTHONPATH谈起
- 初识RecyclerView(二)