problem

345. Reverse Vowels of a String

class Solution {
public:
string reverseVowels(string s) {
int left = , right =s.size()-;
char chl, chr;
while(left<right)
{
if(isVowel(s[left]) &&isVowel(s[right]))
{
char ch = s[left];
s[left++] = s[right];
s[right--] = ch;
}
else if(!isVowel(s[left]))
{
left++;
}
else if(!isVowel(s[right]))
{
right--;
} }
return s; }
bool isVowel(char ch)
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') return true;
else return false;
}
};

注意元音字母不仅有小写,还有大写的。

参考

1. Leetcode_345. Reverse Vowels of a String;

【leetcode】345. Reverse Vowels of a String的更多相关文章

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

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

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

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

  3. 【leetcode】557. Reverse Words in a String III

    Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...

  4. 【LeetCode】151. Reverse Words in a String

    Difficulty: Medium  More:[目录]LeetCode Java实现 Description Given an input string, reverse the string w ...

  5. 【LeetCode】557. Reverse Words in a String III 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

  6. 【LeetCode】151. Reverse Words in a String 翻转字符串里的单词(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.co ...

  7. 【LeetCode】186. Reverse Words in a String II 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 每个单词单独翻转+总的翻转 日期 题目地址:https ...

  8. 【LeetCode】1119. Remove Vowels from a String 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 判断字符是否是aeiou 日期 题目地址:https: ...

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

随机推荐

  1. 创建型模式篇(工厂模式Factory Pattern)

    一.工厂模式(Factory Pattern) 1.定义: 在软件系统,经常面临着“某个对象”的创建工作,由于需求的变化,这个对象的具体实现经常面临着剧烈的变化,但是它却拥有比较稳定的接口.提供一种封 ...

  2. js浮点数相加、减、乘、除精确计算

    js 浮点数计算时 ,无缘无辜 后边冒出一堆 小数点………… 貌似js本身的问题,类型不定?????? 只能自己写函数处理..  http://blog.csdn.net/w4bobo/article ...

  3. python 判断变量是否存在 防止报错

    Python判断变量是否存在 方法一:使用try: ... except NameError: .... try: var except NameError: var_exists = False e ...

  4. linux的命令:

    uname -r  linux的版本号 uname -a  显示系统名.节点名称.操作系统的发行版号.操作系统版本.运行系统的机器 ID 号 cd /dev/ 切换到根目录: ls 查看根目录文件

  5. liunx 随笔集

    Linux 安装时 Customize Now(自定义选包)选包如下 base system  ->  base , compatibility libraries,debugging Tool ...

  6. 执行这些代码, Edit1只能输入数字,小数点和负号,负号和小数点只能输入一个,负号必须在最前,粘贴的数字必须完全正确.

    执行这些代码, Edit1只能输入数字,小数点和负号,负号和小数点只能输入一个,负号必须在最前,粘贴的数字必须完全正确. type TForm1 = class(TForm) Edit1: TEdit ...

  7. lnmp 基础设置

    1.设置ci.tp.laravel重写,去掉index.php location / { try_files $uri $uri/ /index.php?$query_string; } 2.开启ph ...

  8. Linux下使用bind,epoll对网络编程封装

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  9. iOS 10跳转到其他app

    - (BOOL)jumpsToThirdAPP:(NSString *)urlStr{ if ([urlStr hasPrefix:@"mqq"] || [urlStr hasPr ...

  10. Cracking The Coding Interview4.5

    //原文: // // Write an algorithm to find the 'next' node (i.e., in-order successor) of a given node in ...