编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
给定 s = "hello", 返回 "holle".
示例 2:
给定 s = "leetcode", 返回 "leotcede".
注意:
元音字母不包括 "y".
详见:https://leetcode.com/problems/reverse-vowels-of-a-string/description/

C++:

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

参考:https://www.cnblogs.com/grandyang/p/5426682.html

345 Reverse Vowels of a String 反转字符串中的元音字母的更多相关文章

  1. 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] Reverse Vowels of a String 翻转字符串中的元音字母

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...

  3. LeetCode:反转字符串中的元音字母【345】

    LeetCode:反转字符串中的元音字母[345] 题目描述 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "h ...

  4. Java实现 LeetCode 345 反转字符串中的元音字母

    345. 反转字符串中的元音字母 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 ...

  5. [Swift]LeetCode345. 反转字符串中的元音字母 | Reverse Vowels of a String

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...

  6. Leetcode 345. 反转字符串中的元音字母 By Python

    编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: "leet ...

  7. 【leetcode 简单】 第八十三题 反转字符串中的元音字母

    编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: "leet ...

  8. leetCode题解之反转字符串中的元音字母

    1.问题描述 Reverse Vowels of a String Write a function that takes a string as input and reverse only the ...

  9. 【LeetCode】Reverse Words in a String 反转字符串中的单词

    一年没有管理博客园了,说来实在惭愧.. 最近开始刷LeetCode,之前没刷过,说来也实在惭愧... 刚开始按 AC Rates 从简单到难刷,觉得略无聊,就决定按 Add Date 刷,以后也可能看 ...

随机推荐

  1. 洛谷 1937 [USACO10MAR]仓配置Barn Allocation

    [题解] 贪心. 把区间按照右端点从小到大排序,右端点相同的按照长度从小到大排序,然后按顺序考虑,能放就放下去. 维护能不能放下去用线段树即可. #include<cstdio> #inc ...

  2. UVALive 6510 Stickers

    Stickers Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ...

  3. JAVA学习课本内容总结

    二.基本类型 数组 枚举 1.基本类型 逻辑类型 boolean (true/false) 整数类型 byte(8位)  short(16)  int(32)  long(64) 浮点类型 float ...

  4. xcode5修改APP名字

    bundle display name 配置文件里面设置, 这个指的是显示在icon下面的名字.application name在itunes connect上改, 是指显示在app store上的名 ...

  5. srvctl error

    Hit an strange error just now. [oracle@racnode1 ~]$ srvctl # # An unexpected error has been detected ...

  6. 编译Linux使用的.a库文件

    编译Linux使用的.a库文件 首先是须要编译成.a的源文件 hello.h: #ifndef __INCLUDE_HELLO_H__ #define __INCLUDE_HELLO_H__ void ...

  7. Display certain line(s) from a text file in Linux.

    Purpose: Display certain line or lines from a text file, such as : Display the 1000th line from file ...

  8. 【转】java中Thread类方法介绍

    原文: java中Thread类方法介绍 http://blog.csdn.net/seapeak007/article/details/53395609 这篇文章找时间分析一下!!!:http:// ...

  9. 1.3-动态路由协议EIGRP

    EIGRP(Enhanced IGRP) EIGRP的特点: IGRP/EIGRP都是CISCO的私有协议. 1:是唯一的一种LS/DV的混合协议. 2:Rapid convergence EIGRP ...

  10. JobHistory搜索智能化

    前言 做过hadoop集群问题排查工作的同学一定用过JobHistory,这是一个非常好用的"利器",为什么这么说呢?正如这个工具的名称所叫的那样,这个工具能帮你找到历史Job跑过 ...