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

题目大意:

编写函数输入一个字符串,将其中的元音字母逆置。

解题方法:

双指针法(Two Pointers)

注意事项:

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++)的更多相关文章

  1. LeetCode 345. Reverse Vowels of a String(双指针)

    题意:给定一个字符串,反转字符串中的元音字母. 例如: Input: "leetcode" Output: "leotcede" 法一:双指针 class So ...

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

  3. 【leetcode】345. Reverse Vowels of a String

    problem 345. Reverse Vowels of a String class Solution { public: string reverseVowels(string s) { , ...

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

  5. 345. Reverse Vowels of a String - LeetCode

    Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...

  6. 【LeetCode】345. Reverse Vowels of a String 解题报告(Java & Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用栈 双指针 日期 [LeetCode] 题目地址 ...

  7. 【一天一道LeetCode】#345. Reverse Vowels of a String

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

  8. 【leetcode80】Reverse Vowels of a String(元音字母倒叙)

    题目描述: 写一个函数,实现输入一个字符串,然后把其中的元音字母倒叙 注意 元音字母包含大小写,元音字母有五个a,e,i,o,u 原文描述: Write a function that takes a ...

  9. 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. Ubuntu安装secureCRT

    在使用secureCRT前确保主机的ssh服务是启动状态. 一.下载secureCRT包 site:  https://www.vandyke.com/download/securecrt/downl ...

  2. Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法

    在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息: SyntaxError: Non-ASCII character '\xe5' in file ******* 解决方法: py ...

  3. 系统内存和CPU管理、监控

    本博文的主要内容有 .系统内存管理.监控:vmstat和free -mt .系统CPU管理.监控:sar -u.mpstat.uptime linux系统内存和CPU是在系统运行的过程中不断消耗的资源 ...

  4. SparkContext的初始化过程分析(源码)

     SparkContext的构造函数中,最重要的入参是SparkConf  根据初始化入参生成SparkConf 再根据SparkConf来创建SparkEnv TaskScheduler.start ...

  5. Yii中用递归方法实现无限级分类

    用递归方法实现多级分类,适合分级不太多的分类,如三到四级. 数据库结构: Model中(Category.php) /** * 获取全部分类信息 */ public function getAllca ...

  6. Oracle ROWNUM用法和分页查询总结(转)

    [转载] Oracle的分页查询语句基本上可以按照本文给出的格式来进行套用. Oracle分页查询格式(一):http://yangtingkun.itpub.net/post/468/100278 ...

  7. String类、 StringBuffer、基本数据类型对象包装类

    一.概述 Sting s1 = "abc";    //s1是一个类类型变量,"abc"是一个对象. String s2 = new String(" ...

  8. ios9中 UIStackView的使用

    ios9中 UIStackView的使用 by 伍雪颖 UIStackView能够垂直或水平排布多个subview, 自己主动为每一个subview创建和加入Auto Layout constrain ...

  9. CentOS6.4下使用默认的文档查看器打开PDF文档乱码的解决方案

     最近在CentOS6.4下使用其默认的文档查看器打开PDF文档时出现乱码的方块,有两种方法可以解决.    方法一:修改/etc/fonts/conf.d/49-sansserif.conf文件,如 ...

  10. 让iOS开发变得更有效率-分类、工具类

    在工作中整理的一些分类与工具类,分享给大家.这些工具类可以减少项目中的代码量,让代码变得更简洁,可以大大的提升项目的效率,直接拖到项目中使用即可.下载地址:https://github.com/lee ...