Leetcode 345. Reverse Vowels of a String
2016-05-10 17:14
387 查看
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = "hello", return "holle".
class Solution {
public:
string reverseVowels(string s) {
string ss;
for(int i=0;i<s.size();i++){
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'){
ss.push_back(s[i]);
}
}
int len=ss.size();
int j=1;
for(int i=0;i<s.size();i++){
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'){
s[i]=ss[len-j];
j++;
}
}
return s;
}
};
Example 1:
Given s = "hello", return "holle".
class Solution {
public:
string reverseVowels(string s) {
string ss;
for(int i=0;i<s.size();i++){
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'){
ss.push_back(s[i]);
}
}
int len=ss.size();
int j=1;
for(int i=0;i<s.size();i++){
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'){
s[i]=ss[len-j];
j++;
}
}
return s;
}
};
相关文章推荐
- python抓取网页的代码
- View.setBackgroundColor(int color)
- TVCG 简介
- LinkedIn实时低延迟数据抓取系统Databus
- java集合类深入分析之HashSet, HashMap篇
- c++内存分布
- AndroidStudio 在Resolve Error窗体上Failed to import new Gradle projec
- Linux常用命令(四)系统管理命令
- GoogleMap记下:
- 怎么实现ZBrush中的纹理的快速绘制
- linux命令--touch
- Hive中将多个查询结果按行拼接成一张表
- NYOJ 914 Yougth的最大化(贪心,二分)
- linq 动态拼接查询条件 扩展方法
- Maven学习13之覆盖率测试
- SSH无密码登录
- RabbitMQ 集群与高可用配置
- 简单解析JavaScript中的__proto__属性
- 第十一周阅读程序(补充)----(3.2)
- 连接属性