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 ...
随机推荐
- 【转】浅析C语言的非局部跳转:setjmp和longjmp
转自 http://www.cnblogs.com/lienhua34/archive/2012/04/22/2464859.html C语言中有一个goto语句,其可以结合标号实现函数内部的任意跳转 ...
- Java邮件服务学习之四:邮箱服务客户端Spring Mail
一.Spring Mail API Spring邮件抽象层的主要包为org.springframework.mail,Spring提供的邮件发送不仅支持简单邮件的发送.添加附件. 1.邮件发送的核心接 ...
- ACID CAP BASE介绍
ACID ACID,是指数据库管理系统(DBMS)在写入/更新资料的过程中,为保证事务(transaction)是正确可靠的,所必须具备的四个特性:原子性(atomicity,或称不可分割性).一致性 ...
- hibernate中session,HQL,持久化,一对多,多对一
package com.hanqi.test; import java.util.Date; import java.util.List; import org.hibernate.Query; im ...
- Rstudio编辑界面美化设置
美化Rstudio的编辑界面有利于我们输入代码,合适的调整更是减少错误. 可以根据自己的喜好和习惯选择.
- UdpClient的Connect究竟做了什么(转)
最近在写一个音频通信的系统,因为需要还要处理其他事件,所以就自己设计底层的通信协议,用了不少底层的Socket编程(.Net Framework),搞清楚了不少细节问题. 先做一些铺垫工作.音频系统服 ...
- nginx将http重定向到https
1.rewrite server { listen 80; server_name test.com; rewrite ^(.*)$ https://$host$1 permanent; } 2. n ...
- MEF 编程指南(十一):查询 CompositionContainer
CompositionContainer 公开了一部分获取导出.导出对象以及两者集合的重载. 在这些方法重载中,你应该遵循下面的共享行为准则 - 除非特别说明. 当请求单一实例的时候,如果没发 ...
- 搭建sentry(一个分布式日志聚合系统)
简介: Sentry 是一个实时的事件日志和聚合平台,基于 Django 构建. Sentry 可以帮助你将 Python 程序的所有 exception 自动记录下来,然后在一个好用的 UI 上呈现 ...
- slf4j-api-1.7.5日志打印实验
下面一段话来自:百度百科 假设你开发的是类库或者嵌入式组件,那么就应该考虑採用SLF4J,由于不可能影响终于用户选择哪种日志系统.在还有一方面,假设是一个简单或者独立的应用,确定仅仅有一种日志系统,那 ...