Question

345. Reverse Vowels of a String

Solution

思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换。

Java实现:

public String reverseVowels(String s) {List<Integer> store = new ArrayList<>();char[] arr = s.toCharArray();for (int i=0; i< arr.length; i++) {switch (arr[i]) {case 'a':case 'e':case 'i':case 'o':case 'u':case 'A':case 'E':case 'I':case 'O':case 'U':store.add(i);break;}}for (int i=0; i<store.size()/2; i++) {int start = store.get(i);int end = store.get(store.size() - 1 - i);char tmp = arr[start];arr[start] = arr[end];arr[end] = tmp;}return String.valueOf(arr);
}

转载于:https://www.cnblogs.com/okokabcd/p/9236878.html

345. Reverse Vowels of a String - LeetCode相关推荐

  1. LeetCode:345. Reverse Vowels of a String

    051103 题目 Write a function that takes a string as input and reverse only the vowels of a string. Exa ...

  2. 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 1 ...

  3. 【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 1 ...

  4. 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 ...

  5. 【LeetCode】345. Reverse Vowels of a String 解题报告

    转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51429823 Subject 出处:https://leetcode.com/prob ...

  6. Leetcode 345: Reverse Vowels of a String

    问题描述: Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', ...

  7. 345. Reverse Vowels of a String

    题目: Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', ' ...

  8. 345. Reverse Vowels of a String(python+cpp)

    题目: Write a function that takes a string as input and reverse only the vowels of a string. Example 1 ...

  9. Leetcode 345 Reverse Vowels of a String 字符串处理

    题意:倒置字符串中的元音字母. 用两个下标分别指向前后两个相对的元音字母,然后交换. 注意:元音字母是aeiouAEIOU. 1 class Solution { 2 public: 3 bool i ...

最新文章

  1. 敏捷宣言和企业Scrum作者Mike Beedle去世
  2. PHP rewinddir()函数与示例
  3. 【转】20个让Web Developer开发生涯更加轻松的工具
  4. android融云监听消息,关于android:融云-IMkit-拦截或监听所有发送消息
  5. C#.Net工作笔记015---C#中Decimal类型四舍五入_小数点截位
  6. Codeforces Round #198 (Div. 2)A,B题解
  7. jmeter正则表达式提取器_jmeter压测学习4正则表达式提取
  8. SQL数据导入mongodb
  9. ftp文件上传及下载工具类
  10. VirtualBox安装增强工具时:Unable to install guest additions: unknown filesystem type 'iso9660'
  11. 企业号 网页授权 php,微信企业号开发之网页授权接口调用示例
  12. 自学Vue开发Dapp去中心化钱包(一)
  13. LaTeX的正负号写法
  14. PHP输出一段励志的话,100句关于励志的话,青春励志的话,写得好的励志句子
  15. 【ZT】2D动画制作工具比较
  16. CGT Asia 2023第三届亚洲细胞与基因治疗创新峰会将于4月上海召开
  17. 特斯拉股价单日暴跌21% “车企市值第一”短期仍难易主
  18. 六种STM32开发板光盘资料免费下载
  19. 绝地求生FGS小组赛结束,4AM挺进决赛,GoLink_一起为中国战队加油
  20. 4位格雷码的顺序编码_一种基于格雷码的方形QAM星座图编码方法和系统与流程...

热门文章

  1. Windows Terminal v0.7 发布:支持分屏、重排选项卡和改进 UI
  2. 全世界到底有多少软件开发人员?
  3. 实现机器学习的循序渐进指南III——朴素贝叶斯
  4. java 复制文本内容_基于java文本复制的7种方式总结
  5. from mysql partition select_通过分区(Partition)提升MySQL性能[原创翻译]
  6. 我的世界java版如何装mod_Minecraft如何安装Mod?Minecraft添加Mod的方法
  7. linux日志搜索关键词_linux中的实用技巧和快捷键总结
  8. python正则表达式怎么看_python如何使用正则表达式
  9. sqlserver调用mysql存储过程_sqlserver调用存储过程
  10. WPF中如何创建服务