leetcode 345 Reverse Vowels of a String
来源:互联网 发布:js中的保留字有哪些 编辑:程序博客网 时间:2024/04/29 04:24
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
class Solution {public: string reverseVowels(string s) { if(s=="") return s;vector<int> vowels(260, 0);vowels['a']=1;vowels['e']=1;vowels['i']=1;vowels['o']=1;vowels['u']=1;vowels['A']=1;vowels['E']=1;vowels['I']=1;vowels['O']=1;vowels['U']=1;for(int i = 0, j=s.size()-1; i <= j;) {if(vowels[s[i]]==0) {i++;continue;}if(vowels[s[j]]==0) {j--;continue;}if(vowels[s[i]]==1 && vowels[s[j]]==1) {char ch = s[i];s[i] = s[j];s[j] = ch;i++;j--;}}return s; }};
0 0
- Leetcode Reverse Vowels of a String 345
- 【LeetCode-345】Reverse Vowels of a String
- leetcode 345Reverse vowels of a string
- leetcode 345:Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- LeetCode 345:Reverse Vowels of a String
- LeetCode 345: Reverse Vowels of a String
- leetcode 345 Reverse Vowels of a String
- leetcode 345 Reverse Vowels of a String
- LeetCode[345] Reverse Vowels of a String
- Leetcode-345-Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- leetcode 345 Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- LeetCode.345 Reverse Vowels of a String
- leetcode note--leetcode 345 Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- 【JavaScript】文档对象模型(DOM)
- LDA图模型
- 通过端口查看链接数
- 程序员的自我修养读书笔记
- 第二章:probability distribution exericse 35-44
- leetcode 345 Reverse Vowels of a String
- 字段返回null值,却需要进行运算怎么处理?
- C程序内存分配
- cosos2d-x 环境搭建和初学习
- 贩妖记 > 第五十四章,大天机
- MarqueeView源码简单分析笔记
- Android 5.0以后启动服务的正确做法
- C++的头文件和实现文件分别写什么
- 如何使用GCC编译器