【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".
应该算不上有难度。
class Solution { public:string reverseVowels(string s) {string str = s;for (int i = 0, j = str.size() - 1; i < j; ){if (isVowel(str[i]) && isVowel(str[j])) {char tmp = str[i];str[i] = str[j];str[j] = tmp;i++;j--;}if ( !isVowel(str[i]))++i;if ( !isVowel(str[j])) --j;}return str;}bool isVowel(char c) {if (c == 'a' || c == 'e' || c == 'i' || c == 'u' || c == 'o' \|| c == 'A' || c == 'E' || c == 'I' || c == 'U' || c == 'O') return true;return false;} };
转载于:https://www.cnblogs.com/Doctengineer/p/5866768.html
【LeetCode】345. Reverse Vowels of a String 解题小结相关推荐
- 【LeetCode】345. Reverse Vowels of a String 解题报告
转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51429823 Subject 出处:https://leetcode.com/prob ...
- 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
题目: 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
问题描述: 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 ...
- 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 ...
最新文章
- 总在说SpringBoot内置了tomcat启动,那它的原理你说的清楚吗?
- python的self
- MySQL-8.0.12源码安装实例
- 330 div+css Experience
- ICCV 2019 | 旷视研究院提出文字检测新方法:像素聚合网络PAN
- “常程跳槽小米”裁决出炉:常程继续履行竞业限制,还要赔500多万...
- 苹果7支持快充吗_iPhone12的磁吸无线充到底怎么回事?是否支持苹果20W快充?
- 【React性能优化】 redux优化
- 拓端tecdat|R语言时变向量自回归(TV-VAR)模型分析时间序列和可视化
- Ansible 自动化运维工具
- 林軒田《机器学习基石》课程总结
- 无线ac配置dhcp服务器,华硕RT-AC86U路由器怎么设置DHCP功能
- linux系统苹果刷机,iPhone上安装Android系统详细步骤
- bugku--never_give_up
- 怎么用python将日期转化为数字_python转化excel数字日期为标准日期操作
- 一张照片让你的安卓手机崩溃
- 计算机考研用python_2014北邮计算机考研复试上机题解(上午+下午)
- YoloV4当中的Mosaic数据增强方法(附代码讲解)
- 2022公司邮箱登录入口官网介绍,个人邮箱用户登录
- Fatal NI connect error 12170错误解决办法