345. Reverse Vowels of a String(C++)
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".
题目大意:
编写函数输入一个字符串,将其中的元音字母逆置。
解题方法:
注意事项:
C++代码:
class Solution {
public:
string reverseVowels(string s) {
int left=;
int right=s.size()-;
string t="aeiouAEIOU";
while(left<right)
{
if(t.find(s[left])==string::npos)
{
++left;
}
else if(t.find(s[right])==string::npos)
{
--right;
}
else
{
swap(s[left++],s[right--]);
}
}
return s;
}
};
345. Reverse Vowels of a String(C++)的更多相关文章
- LeetCode 345. Reverse Vowels of a String(双指针)
题意:给定一个字符串,反转字符串中的元音字母. 例如: Input: "leetcode" Output: "leotcede" 法一:双指针 class So ...
- leetcode345——Reverse Vowels of a String(C++)
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- 【leetcode】345. Reverse Vowels of a String
problem 345. Reverse Vowels of a String class Solution { public: string reverseVowels(string s) { , ...
- 345. Reverse Vowels of a String【easy】
345. Reverse Vowels of a String[easy] Write a function that takes a string as input and reverse only ...
- 345. Reverse Vowels of a String - LeetCode
Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...
- 【LeetCode】345. Reverse Vowels of a String 解题报告(Java & Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用栈 双指针 日期 [LeetCode] 题目地址 ...
- 【一天一道LeetCode】#345. Reverse Vowels of a String
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
- 【leetcode80】Reverse Vowels of a String(元音字母倒叙)
题目描述: 写一个函数,实现输入一个字符串,然后把其中的元音字母倒叙 注意 元音字母包含大小写,元音字母有五个a,e,i,o,u 原文描述: Write a function that takes a ...
- 345. Reverse Vowels of a String翻转字符串中的元音字母
[抄题]: Write a function that takes a string as input and reverse only the vowels of a string. Example ...
随机推荐
- C++ 把输出结果写入文件/从文件中读取数据
先包含头文文件 #include<fstream> 输出到文件 ofstream fout; //声明一个输出流对象 fout.open("output.txt"); ...
- Java Networking: InetAddress
The InetAddress is Java's representation of an IP address. Instances of this class are used together ...
- 从MSN上拔下来的全世界国家下拉框(附带SQL执行脚本)
<select> <option value="AL">阿尔巴尼亚</option> <option value="DZ&quo ...
- HDU 2102 A计划(三维BFS)
这题太欢乐了......虽然wa了几次,但是想到骑士在两幅图的传送门中传来传去就觉得这骑士太坑了 #include <cstdio> #include <iostream> # ...
- Android应用开发学习之表格视图
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来学习一个使用表格视图的程序,下图是该程序的运行效果: 该程序主Activity文件内容如下: packag ...
- jQuery 的属性操作方法
jQuery 属性操作方法 下面列出的这些方法获得或设置元素的 DOM 属性. 这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html(). 方法 描述 addClass() 向匹配的 ...
- 第一个小项目(天气预报软件)——称"酷狗天气"
一.创建数据库和表 分析: 二.遍历全国省市县数据 分析: 三.显示天气信息 分析: 四.切换城市和手动更新天气 分析: 五.后台自动更新天气 分析:
- java synchronized与volatile的区别
java线程同步有两个特性,一个是可见性,一个是有序性.在解释这两个概念之前,先说下两个重要的概念,主内存(main memory)和工作内存(working memory),线 程之间数据的交互不是 ...
- poj 1226
跟3294比较类似,但是不需要输出具体的串,比较简单,只要把串反转连接上去解法就一样了. #include <iostream> #include <cstdio> #incl ...
- 怎样使用SetTimer MFC 够具体
转自:http://blog.csdn.net/ellor/article/details/1714741 Timer事件,即定时器事件,是在游戏编程中,常常使用的一个事件.借助它能够产生定时运行动作 ...