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

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

注意:元音字母是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. 关于Android的布局

    Android中五大布局是直接继承ViewGroup的布局:RelativeLayout.GridLayout.FrameLayout.AbsoluteLayout.LinnerLayout(Tabl ...

  2. 很实用的jQuery事件 - toggle() 方法

    实例 切换不同的背景色: $("p").toggle( function(){ $("body").css("background-color&quo ...

  3. npoi实现 从固定的行读取数据作为表头并返回datable

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  4. Spring 4 官方文档学习(十一)Web MVC 框架之编码式Servlet容器初始化

    在Servlet 3.0+ 环境中,你可以编码式配置Servlet容器,用来代替或者结合 web.xml文件.下面是注册DispatcherServlet : import org.springfra ...

  5. 主DNS配置

    一,安装BIND [root@localhost ~]# yum install bind bind-chroot bind-utils Loaded plugins: product-id, sub ...

  6. mysql and 和 or 的 优先级和 查询问题

    1. select * from trade where id=1 and cid=1 or pid=2 ; 2. select * from trade where cid=1 or (pid=2 ...

  7. xcode8 导入 dylib

    点击 add others shift + command + g

  8. 专题:Channel Bonding/bonding

    EtherChannel最初是由cisco提出,通过聚合多条物理链路为单条逻辑链路,从而实现高可用及提高吞吐量等目的.AgP(Port Aggregation Protocol,Cisco专有协议). ...

  9. HTML5的touch事件

    HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事件主 ...

  10. javascript 对象属性的get set访问器写法

    function Person() {     var age = new Date().getFullYear() - 18;     Object.defineProperty(this, &qu ...