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 ...
随机推荐
- rem 和 ::
-------siwuxie095 rem 和 :: 都是用作批处理注解(等同于各种编程语言中的注释) 注解批处理时,标准写法是写在被注解代码的上一行 REM 在批处理文件或CONFIG.SYS里 ...
- Entity Framework 6.0 源码解读笔记(一)
internal static TResult ExecuteSingle<TResult>(IEnumerable<TResult> query, Expression qu ...
- Delphi inline编译器优化问题
function Test():Integer; inline; var P:Pointer; begin FreeMem(P); Result := AtomicIncrement(__gr); / ...
- SpringMVC与ajax相关知识练习与存档
参考文章(亲测有效): SpringMVC+ajax返回JSON串 jquery ajax例子返回值详解 AJAX $.ajax({url:路径,date:数据,}) //get请求(指定回调函数,参 ...
- css页面点击文字出现蓝色底色去掉方法
-moz-user-select: none; /*火狐*/ -webkit-user-select: none; /*webkit浏览器*/ -ms-user-select: non ...
- 【java】:解析xml
==========================================xml文件<?xml version="1.0" encoding="GB231 ...
- Jade之条件语句
条件语句 jade支持js中的if/elseif/else语法. jade: - var user = { description: 'foo bar baz' } - var authorised ...
- Java中FileOutputStream和FileInputStream使用例子
package a.ab; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.F ...
- Robots on a grid(DP+bfs())
链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25585 Current Server Time: 2013-08-27 20:42:26 Ro ...
- java基础知识分析: final , finally,finalize
final final-修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承.因此一个类不能既被声明为 abstract的,又被声明为final的.将变量或方 ...