【leetcode】345. Reverse Vowels of a String
problem
345. Reverse Vowels of a String
class Solution {
public:
string reverseVowels(string s) {
int left = , right =s.size()-;
char chl, chr;
while(left<right)
{
if(isVowel(s[left]) &&isVowel(s[right]))
{
char ch = s[left];
s[left++] = s[right];
s[right--] = ch;
}
else if(!isVowel(s[left]))
{
left++;
}
else if(!isVowel(s[right]))
{
right--;
}
}
return s;
}
bool isVowel(char ch)
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') return true;
else return false;
}
};
注意元音字母不仅有小写,还有大写的。
参考
1. Leetcode_345. Reverse Vowels of a String;
完
【leetcode】345. Reverse Vowels of a String的更多相关文章
- 【LeetCode】345. Reverse Vowels of a String 解题报告(Java & Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用栈 双指针 日期 [LeetCode] 题目地址 ...
- 【一天一道LeetCode】#345. Reverse Vowels of a String
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
- 【leetcode】557. Reverse Words in a String III
Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...
- 【LeetCode】151. Reverse Words in a String
Difficulty: Medium More:[目录]LeetCode Java实现 Description Given an input string, reverse the string w ...
- 【LeetCode】557. Reverse Words in a String III 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...
- 【LeetCode】151. Reverse Words in a String 翻转字符串里的单词(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.co ...
- 【LeetCode】186. Reverse Words in a String II 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 每个单词单独翻转+总的翻转 日期 题目地址:https ...
- 【LeetCode】1119. Remove Vowels from a String 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 判断字符是否是aeiou 日期 题目地址:https: ...
- 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】成对交换节点
e.g. 给定链表 1->2->3->4,返回 2->1->4->3 的头节点. 我写了个常见的从头节点遍历,少量的奇数个或偶数个数据都能成功重新排列.但链表过长时 ...
- JTA 使用 MySQL 分布式事务
假定在MySQL实例1上有表 create table person( id int, name ) ) MySQL实例2上也有一张同样的表,现在从实例1中的 person 表中删除一条数据,并把这条 ...
- utf8mb4与utf8的区别
今天在测试小程序保存表情时,数据库插入数据时报错ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value: '\xF0\x9F\x98\x8 ...
- 将16进制unsigned char数组转换成整数
/** * 将unsigned char数组转换成long long数值 * {0x00 0x00 0x20 0x00}转换之后得到8192 * * @param str 数组 * @param le ...
- jquery自定义类的封装
如何用jquery自定义一个类?(demo参考) /*简单使用*/ (function($){ //el操纵对象,option属性值 $.love = function(el,option){ var ...
- Linux第二周作业
通过反汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的 1.进入vi编写C语言程序代码,首先必须输入命令vi main,c,其中main.c是文件名. 紧接着按esc键退出编辑状态,再输入一个 ...
- spring bean 的生命周期
感谢博友,内容源于博友的文章 http://www.cnblogs.com/zrtqsk/p/3735273.html 通过了解spring的bean 的生命周期 ,再结合jdk的注解,继承sprin ...
- angular4-注入服务
//配置已创建的服务:import { MemberService } from "./member.service";@NgModule({ // ... providers: ...
- mysql存储过程中使用游标
用户变量一般以@开头,作用于全局范围 局部变量需用 declare 定义格式为 declare 变量名 数据类型 [default value]; mysql 数据类型有 int ,float,dat ...
- TypeError: write() argument must be str, not bytes报错原因及Python3写入二进制文件方法
Python2随机写入二进制文件: with open('/python2/random.bin','w') as f: f.write(os.urandom(10)) 但使用Python3会报错: ...