Leetcode 345 Reverse Vowels of a String 字符串处理
题意:倒置字符串中的元音字母。
用两个下标分别指向前后两个相对的元音字母,然后交换。
注意:元音字母是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 字符串处理的更多相关文章
- 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 ...
- 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 ...
- LeetCode 345. Reverse Vowels of a String(双指针)
题意:给定一个字符串,反转字符串中的元音字母. 例如: Input: "leetcode" Output: "leotcede" 法一:双指针 class So ...
- Leetcode 345 Reverse Vowels in a String
两个for 第一个for将每一个元音依次存放进一个char数组 第二个for,每检测到元音,就从char数尾部开始,依次赋值 如何检测元音呢?当然写一个冗长的if(),不过我们有更好的选择 hashs ...
- 【leetcode】345. Reverse Vowels of a String
problem 345. Reverse Vowels of a String class Solution { public: string reverseVowels(string s) { , ...
- 345. Reverse Vowels of a String - LeetCode
Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...
- 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 ...
- 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 ...
- 【一天一道LeetCode】#345. Reverse Vowels of a String
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
随机推荐
- [原创][LaTex]LaTex学习笔记入门
0. 简介 LaTEX(/ˈlɑːtɛx/,常被读作/ˈlɑːtɛk/或/ˈleɪtɛk/),文字形式写作LaTeX,是一种基于TEX的排版系统,由美国电脑学家莱斯利·兰伯特在20世纪80年代初期开发 ...
- weblogic myeclipse小知识
新建域 http://jingyan.baidu.com/article/f7ff0bfc72904e2e27bb136f.html svn 上down下来一些新项目的时候没法添加到weblogic ...
- ArcGIS删除部分数据后全图范围不正确
我有一个全国地图的图层,现在删除图层中其他省份,只保留山东省的图形,但是点击全图后,全图范围仍然是全国地图时候的全图范围,使用的版本是ArcGIS9.3,数据存放在9.3的个人数据库中(Perso ...
- XE3随笔7:可以省略的双引号
在 JSON 中, 字符串应该在双引号中; 从上个例子才发现: 原来这个双引号可以省略, 有空格都行 当然只是在程序代码中可以省略, 对象会自动识别添加的. 即如此, 下面写法都可以: uses Su ...
- PRISM ‘VS100COMNTOOLS’ not set. Cannot set the build environment
prism 注册dll,出现以上错误 在系统环境变量,增加 VS100COMNTOOLS 设置路径C:\Program Files (x86)\Microsoft Visual Studio 11.0 ...
- Server Transfer()和Response.Redirect()的使用
一.Server Transfer() Server.Transfer:对于当前请求,终止当前页的执行,并使用指定的页url路径来开始执行一个新页. 1. Server.Transfer只能够转跳到本 ...
- c# 框架学习(nop )总结-------删除功能
删除直接使用(框架中以封装好的) 控制中写就可以啦 public ActionResult Delete(int id) { //权限位置(若需要的话)var individual = _indivi ...
- 1055: [HAOI2008]玩具取名
Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后 他会根据自己的喜好,将名字中任意一个字母用"WING" ...
- Java 关键字、标识符、注释、常量与变量、数据类型,算术、赋值、比较、逻辑、位、三元运算符和流程控制、break、continue【3】
若有不正之处,请多多谅解并欢迎批评指正,不甚感激.请尊重作者劳动成果: 本文原创作者:pipi-changing本文原创出处:http://www.cnblogs.com/pipi-changing/ ...
- Masonry 轻量级布局框架的使用
iOS 提供了自动布局的方法,但是原生的方法使用太过麻烦 ,Masonry 框架提供了类似的方法,同样可以实现自动布局 ,代码更加直观,而且容易理解. Masonry 是一个轻量级的布局框架.拥有自己 ...