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

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

注意:元音字母是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. MJExtension 中model嵌套Model

    + (NSDictionary *)objectClassInArray { return @{@"comment": [Comment class]};}

  2. Notepad++ 快捷键 大全

    Notepad++ 快捷键 大全Ctrl+C 复制Ctrl+X 剪切Ctrl+V 粘贴Ctrl+Z 撤消Ctrl+Y 恢复Ctrl+A 全选Ctrl+F 键查找对话框启动Ctrl+H 查找/替换对话框 ...

  3. Java 测试URL地址是否能正常连接

    public static int testWsdlConnection(String address) throws Exception { int status = 404; try { URL ...

  4. Excel表格常用的函数,留着备用

    1. vlookup(lookup_value, table_array, col_index_num, boolean) -- 查找匹配函数 lookup_value: 你要去匹配的值 table_ ...

  5. linux笔记-硬链接和符号链接

    硬链接:指多个路径名(不同目录下的不同文件名)指向同一个硬盘数据,用其中的随便哪个文件打开修改数据,都会在其他文件打开中更新, 原因就是硬链接和“原”文件inode相同,每增加或者删除一个链接,链接计 ...

  6. DataTime格式化大全(转载)

    //c datetime 格式化 DateTime dt = DateTime.Now; Label1.Text = dt.ToString();//2005-11-5 13:21:25 Label2 ...

  7. 关于VMWARE 上对于不小心VMWare Tools Easy Install 后卡死的解决方法

    PS 要想修改首先开机的时候会进入命令行,输入用户名,密码后,可以用startx来进入图形界面(也有人将/etc/init.d/ligtmd start可以懂事本人那次是不行的) 通常网上人们的解决办 ...

  8. (转)四种常见的 POST 提交数据方式

    四种常见的 POST 提交数据方式(转自:https://imququ.com/post/four-ways-to-post-data-in-http.html) HTTP/1.1 协议规定的 HTT ...

  9. MYSQL基础--学习笔记

    最近一段时间,系统的学习了下mysql相关知识,当然都是比较基础的,现在贴出来,以供参考备忘--帅帅的小猪猪 创建用户:CREATE USER 'sampadm'@'localhost' IDENTI ...

  10. HIVE几种数据导入方式

    HIVE几种数据导入方式 今天的话题是总结Hive的几种常见的数据导入方式,我总结为四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询 ...