<LeetCode OJ> 345. Reverse Vowels of a String
2016-04-23 20:35
309 查看
Total Accepted: 537 Total
Submissions: 1488 Difficulty: Easy
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".
Subscribe to see which companies asked this question
Hide Tags
Two Pointers String
Hide Similar Problems
(E) Reverse String
分析:
典型的双指针问题,注意边界条件即可!
注:本博文为EbowTang原创,后续可能继续更新本文。如果转载,请务必复制本条信息!
原文地址:http://blog.csdn.net/ebowtang/article/details/51228095
原作者博客:http://blog.csdn.net/ebowtang
本博客LeetCode题解索引:/article/3664871.html
Submissions: 1488 Difficulty: Easy
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".
Subscribe to see which companies asked this question
Hide Tags
Two Pointers String
Hide Similar Problems
(E) Reverse String
分析:
典型的双指针问题,注意边界条件即可!
class Solution { public: void swapchar(string &str,int pos1,int pos2) { char tmpch=str[pos2]; str[pos2]=str[pos1]; str[pos1]=tmpch; } string reverseVowels(string s) { char base[10]={'a','e','i','o','u','A','E','I','O','U'}; set<char> seting(base,base+10); int startpos=0,endpos=s.size()-1; while(startpos < endpos ) { while( startpos < endpos && seting.find(s[startpos]) == seting.end())//从左往右、新的、未被交换过的元音位置 startpos++; while( startpos < endpos && seting.find(s[endpos]) == seting.end()) endpos--; if(startpos < endpos) swapchar(s,startpos++,endpos--); } return s; } };
注:本博文为EbowTang原创,后续可能继续更新本文。如果转载,请务必复制本条信息!
原文地址:http://blog.csdn.net/ebowtang/article/details/51228095
原作者博客:http://blog.csdn.net/ebowtang
本博客LeetCode题解索引:/article/3664871.html
相关文章推荐
- LTE-TDD随机接入过程(6)-分场景描述竞争接入和非竞争接入的流程
- 用js判断复选框(checkbox)是否选中的问题
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 上传
- 初用webUploader学习笔记
- 《人件》文摘
- DFS 搜索 Problem 1016 Red and Black
- Python爬虫开发
- MySQL基础1
- #leetcode#191 Number of 1 Bits n&n-1的用处
- Socket-Programing-FAQ
- CSU 1541 There is No Alternative【最小生成树+思维】
- Storm 初步
- 使用JAVA 实现jpg/tif/bmp 等图片之间格式得互相转换
- CVTRES : fatal error CVT1100: 资源重复。类型: MANIFEST,名称: 1,语言: 0x0409 LINK : fatal error LNK1123: 转换到 COF
- 出差(2~十六)
- 那些关于C语言的一些事
- 北师校赛,三号题目Squared Permutation, 映射+线段树
- 阿里巴巴电话面试2面总结_数据挖掘工程师(天猫事业部)
- 堆(heap)和栈(stack)有什么区别?