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 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
/*************************************************************************
> File Name: LeetCode345.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: Tue 10 May 2016 08:55:33 PM CST
************************************************************************/ /************************************************************************* Reverse Vowels of a String Write a function that takes a string as input
and reverse only the vowels of a string. Example 1:
Given s = "hello", return "holle". Example 2:
Given s = "leetcode", return "leotcede". ************************************************************************/ #include <stdio.h> int isVowels( char s )
{
int flag = ;
if( s=='a' || s=='e' || s=='i' || s=='o' || s=='u' || s=='A' || s=='E' || s=='I' || s=='O' || s=='U' )
{
flag = ;
}
return flag;
} char* reverseVowels( char* s )
{
int left = ;
int right = strlen(s) - ; printf("%c %c\n", s[left], s[right]);
char temp; while( left < right )
{
printf("%d %d\n", left, right);
if( isVowels(s[left]) == )
{
if( isVowels(s[right]) == )
{
temp = s[left];
s[left] = s[right];
s[right] = temp; left ++;
right--;
printf("%s\n", s);
}
else
{
right--;
}
}
else
{
left ++;
}
}
return s;
} int main()
{
char* s = "leetcode";
printf("%s\n", s);
char* reverseS = reverseVowels(s);
printf("%s\n", s); return ;
}
LeetCode 345的更多相关文章
- Java实现 LeetCode 345 反转字符串中的元音字母
345. 反转字符串中的元音字母 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 ...
- 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 ...
- 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. 反转字符串中的元音字母 By Python
编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: "leet ...
- [LeetCode] 345. Reverse Vowels of a String_Easy tag:Two Pointers
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...
- LeetCode 345. Reverse Vowels of a String(双指针)
题意:给定一个字符串,反转字符串中的元音字母. 例如: Input: "leetcode" Output: "leotcede" 法一:双指针 class So ...
- Leetcode 345 Reverse Vowels of a String 字符串处理
题意:倒置字符串中的元音字母. 用两个下标分别指向前后两个相对的元音字母,然后交换. 注意:元音字母是aeiouAEIOU. class Solution { public: bool isVowel ...
- Leetcode 345 Reverse Vowels in a String
两个for 第一个for将每一个元音依次存放进一个char数组 第二个for,每检测到元音,就从char数尾部开始,依次赋值 如何检测元音呢?当然写一个冗长的if(),不过我们有更好的选择 hashs ...
- Leetcode 125 Valid Palindrome 字符串处理
题意:判断字符串是否是回文字符串 先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同. 该题最好的解法可以模仿 Leetcode 345 Rever ...
随机推荐
- Nginx的代理和反向代理
什么是代理? 代理是为网络用户代理了来访问网络的,比如Google agent代理FQ. 什么是反向代理? 以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服 ...
- codeforces 630A Again Twenty Five!
A. Again Twenty Five! time limit per test 0.5 seconds memory limit per test 64 megabytes input stand ...
- sql server 2014内存表
内存数据库,指的是将数据库的数据放在内存中直接操作.相对于存放在磁盘上,内存的数据读写速度要高出很多,故可以提高应用的性能.微软的SQL Server 2014已于2014年4月1日正式发布,SQL ...
- 使用paramiko进行打包操作
使用paramiko执行ssh命令的时候有一个很坑爹的地方:它无法准确的识别你的系统环境变量,所以使用一些命令的时候会发现,直接在系统中执行该命令的时候可以,但是换成paramiko执行的时候会报错说 ...
- CodeForces 589D Boulevard (数学,相遇)
题意:给定 n 个的在 x 轴上的坐标,和开始时间,结束坐标,从起点向终点走,如果和其他人相遇,就互相打招乎,问你每人打招乎的次数. 析:其实这一个数学题,由于 n 比较小,我们就可以两两暴力,这两个 ...
- Linux下修改用户home目录
一般在Linux上新建一个用户,会在/home目录下自动创建一个以用户名命名的home目录 修改linux下用户自动建立的家目录 vi编辑器打开/etc/default/useradd 这个文件,然后 ...
- Castle IOC容器实践之FactorySupport Facility
PDF版本下载:http://file.ddvip.com/2008_10/1223538519_ddvip_4853.rar示例代码下载:http://file.ddvip.com/2008_10/ ...
- Mysql中关于 group_concat函数详解
group_concat()主要功能:能将相同的行组合起来 完整的语法如下: group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Sepa ...
- 让EditText不能自动获取焦点
在activity中放置了1个或1个以上的EditText,进入该activity的时候第一个EditText会接收焦点,我希望里面所有的EditText默认是不接收焦点的,该怎么做呢? 方法: 在第 ...
- zookeeper的C#Client
最近在搭一套soa, 服务使用java/scala 的finagle 协议使用thrift 然后 finagle默认服务端会是使用zookeeper作为节点存储.. 所以想要访问具体服务,需要先通过 ...