题意:倒置字符串中的元音字母。

用两个下标分别指向前后两个相对的元音字母,然后交换。

注意:元音字母是aeiouAEIOU。

 class Solution {
public:
bool isVowels(char c){
string Vowels = "aeiouAEIOU";
for(int i = ; i < Vowels.size(); ++i){
if(c == Vowels[i]) return true;
}
return false;
}
string reverseVowels(string s) {
int i = , j = s.size() - ;
while(i < j){
if(!isVowels(s[i])) ++i;
if(!isVowels(s[j])) --j;
if(isVowels(s[i]) && isVowels(s[j])){
swap(s[i],s[j]);
++i,--j;
}
}
return s;
}
};

Leetcode 345 Reverse Vowels of a String 字符串处理的更多相关文章

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

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

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

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

  4. Leetcode 345 Reverse Vowels in a String

    两个for 第一个for将每一个元音依次存放进一个char数组 第二个for,每检测到元音,就从char数尾部开始,依次赋值 如何检测元音呢?当然写一个冗长的if(),不过我们有更好的选择 hashs ...

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

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

  6. 345. Reverse Vowels of a String - LeetCode

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

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

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

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

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

随机推荐

  1. 在Linux中的文本模式下手动安装 Parallels Tools

    1.启动虚拟机. 2.当看到提示 X Server 无法启动的消息时,使用 Ctrl+Option+F1(Ctrl+Alt+F1)切换到另一个虚拟控制台并输入登录信息. 3 从“虚拟机”菜单中选择“安 ...

  2. Hibernate之创建命名策略

    在开发软件时,通常会要求每个开发人员遵守共同的命名策略.例如,数据库的表名及字段名的所有字符都要大写,表名以“S”结尾.对于Customer类,对应的数据库表名为CUSTOMERS.为了在映射文件中遵 ...

  3. Ubuntu10.0.4安装NDK

    android版本遇到.so文件crash,需要使用ndk来定位报错代码. 从这里下载ndk安装文件: http://www.androiddevtools.cn/ 运行 ./android-ndk- ...

  4. oracle安装心得

    1.官网下载 oracle 11g r2 2.官网下载的oracle包括两个文件夹file1和file2,需要将解压后的file2中的stage-components文件夹下的内容复制到file1-s ...

  5. 【OpenGL】VS2010环境配置 [转]

    基于OpenGL标准开发的应用程序运行时需有动态链接库OpenGL32.DLL.Glu32.DLL,这两个文件在安装Windows NT时已自动装载到C:\WINDOWS\SYSTEM32目录下(这里 ...

  6. PHP 数组排序

    数组中的元素能够以字母或数字顺序进行升序或降序排序. PHP - 数组的排序函数 在本节中,我们将学习如下 PHP 数组排序函数: sort() - 以升序对数组排序 rsort() - 以降序对数组 ...

  7. 网页中插入swf动画(embed)

    网页中插入swf动画(embed:[ɪm'bed]) 例题: <embed src="swf.sef" width="200" height=" ...

  8. 【Visual Lisp】驱动器、目录、文件和注册表

    ;;驱动器.目录.文件.和注册表;;★★★01.获取并创建驱动器盘符组成的表★★★(setq Drives (vlax-get-property (vlax-create-object "S ...

  9. json jackson

    1.引入依赖 <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId&g ...

  10. Ubuntu14.04-PXE装机笔记

    什么是PXE? PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从 ...