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. 你需要知道的10位Java开发牛人

    1.James Gosling 1983 年,Gosling 获得了加州大学的计算机科学学士学位.1990 年,他获得了卡内基梅隆大学的计算机科学博士学位,师从 BobSproull.在攻读博士期间, ...

  2. UVA 10256 The Great Divide (凸包,多边形的位置关系)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34148 [思路] 凸包 求出红蓝点的凸包,剩下的问题就是判断两个凸 ...

  3. Python串口操作纸币器1

    公司需要纸币器开发,参考纸币器文档和网上的一篇vb版本,代码如下: # -*- coding:utf-8 -*- # Author: Pete Yim<xpHook@gmail.com> ...

  4. Ruby on Rails Session 2: How to install Aptana Studio 3 on Ubuntu 12.04 LTS

    Update: An updated version of these instructions for Ubuntu 12.10 (Quantal Quetzal) is available her ...

  5. 从源码编译rpi的内核

    Kernel Building https://www.raspberrypi.org/documentation/linux/kernel/building.md There are two mai ...

  6. PG数据库之间的导入导出

    本文将介绍如何对PG数据库进行导入.导出,主要利用的是PG自带的pg_dump.pg_dumpall.pg_restore.psql等命令,版本是9.4(不同版本的pg_dump \ pg_resto ...

  7. spring集成guava的event bus

    Guava的event bus guava, https://github.com/google/guava 是一个非常有名的Java类库,提供了很多在日常开发中常用的集合.函数接口等.此外,guav ...

  8. Can't connect to MySQL server on localhost (10061)解决方法

    出现这种错误的原因是由于MySQL的服务被关闭的原因,重新启动一下服务就可以了,启动服务的操作如下: 右键[计算机]-[管理]

  9. [TypeScript] Reflection and Decorator Metadata

    TypeScript allows you to emit decorator metadata which enables more powerful features through reflec ...

  10. MYSQL 学习笔记1 -----mysqladmin -uroot -p status|extended-status

    root@server1 ~]# mysqladmin -uroot -p status -i -r extended-status|grep Handler_commit Enter passwor ...