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:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
Note:
The vowels does not include the letter "y".
要完成的函数:
string reverseVowels(string s)
说明:
1、题目不难看懂,从字符串首部开始找,找到的第一个元音和,从字符串尾部开始找,找到的第一个元音交换位置。接着继续找第二个……直到所有元音都反转完成。
2、元音是“a”、“e“、“i”、“o”、“u”以及它们的大写形式。
3、令i=0,j=s.size()-1,不断查找并且交换位置,最终退出循环条件是i>=j。
代码如下:
string reverseVowels(string s) {int i=0,j=s.size()-1;while(i<j){if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'){while(i<j){if(s[j]=='a'||s[j]=='e'||s[j]=='i'||s[j]=='o'||s[j]=='u'||s[j]=='A'||s[j]=='E'||s[j]=='I'||s[j]=='O'||s[j]=='U'){swap(s[i],s[j]);j--;break;}j--;}}i++;}return s;}
上述代码实测12ms,beats 86.45% of cpp submissions。
转载于:https://www.cnblogs.com/chenjx85/p/8858837.html
leetcode-345-Reverse Vowels of a String相关推荐
- 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 ...
- 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 ...
- 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', ...
- Leetcode 345 Reverse Vowels of a String 字符串处理
题意:倒置字符串中的元音字母. 用两个下标分别指向前后两个相对的元音字母,然后交换. 注意:元音字母是aeiouAEIOU. 1 class Solution { 2 public: 3 bool i ...
- 345. Reverse Vowels of a String - LeetCode
Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...
- 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 ...
- 【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 ...
- 【LeetCode】345. Reverse Vowels of a String 解题报告
转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51429823 Subject 出处:https://leetcode.com/prob ...
- 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', ' ...
- 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 ...
最新文章
- css标签显示特性(块级元素、行内元素、行内块元素、标签显示模式转换display、简单文字居中、简单导航栏案例)
- Maven学习总结(九)——使用Nexus搭建Maven私服
- 【 MATLAB 】使用案例研究 DTFT 的对称性
- Java Web 前端高性能优化(二)
- nginx配置location总结及rewrite规则写法
- 【架构二】后端高可用架构演进
- HBase+Phoenix整合入门--集群搭建
- osx php7 imagick,[PHP] MacOS 自带php环境安装imagick扩展踩坑记录 | 码农部落
- html怎么使图片无法另存为,如何禁止图片另存为?禁止网页另存为到本地的方法...
- 【转】WPF从我炫系列3---内容控件的用法
- python123第五章_python 3.5学习笔记(第五章)
- 如何在golang http服务端程序中读取2次Request Body?(转)
- Linux三剑客grep、sed、awk
- 3-1-Servlet技术
- Python实现大自然数分解为最多4个平方数之和(1)
- python文件读写及形式转化和CGI的简单应用
- ES6与ES2015、ES2016以及ECMAScript的区别
- java final关键字
- 前端面经 | 腾讯实习生校招面试心路历程
- 原标题:跆拳道在中国斗殴中被武术团灭?韩国人看后表示不服
热门文章
- AgileEAS.NET SOA 中间件Web运行容器管理功能已全部开源,欢迎大家下载、使用、反馈...
- Git学习笔记(四)
- fck2.6.3配置
- 【python】面向对象类的继承
- inner join 与 left join 之间的区别
- java deployment_deployment简略介绍
- postman在线测试_如何选择适合自己的自动化测试工具?
- mysql的number类型对应的db2_【转】oracle数据库NUMBER数据类型
- 26岁零基础转行学习前端可以找到工作吗?
- 转行学编程,女孩子适合web前端还是Java?