LeetCode-345. Reverse Vowels of a String
来源:互联网 发布:ibm蓝云计算平台 编辑:程序博客网 时间:2024/06/15 04:15
问题:https://leetcode.com/problems/reverse-vowels-of-a-string/?tab=Description
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”.
Note:The vowels does not include the letter “y”.
分析:调用函数,先判断是否为元音字母。头的和尾的调转。
C++代码:
class Solution {public: string reverseVowels(string s) { int i=0; int j=s.length()-1; while(i<j){ while(isVowel(s[i])==false && (i<j)){ i++; } while(isVowel(s[j])==false && (i<j)){ j--; } swap(s[i],s[j]); i++; j--; } return s; } bool isVowel(char c){ if((c=='a') ||(c=='e')||(c=='i')||(c=='o')||(c=='u')||(c=='A')||(c=='E')||(c=='I')||(c=='O')||(c=='U')) return true; else return false; }};
0 0
- 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
- 345.[LeetCode]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
- jsoup分析出绝对路径(转)
- HDU 4121 Xaingqi
- Java注释
- 根路径文件是否存在
- LeetCode--4
- LeetCode-345. Reverse Vowels of a String
- 使用Sencha cmd安装extjs6
- CKEditor图片上传的PHP实现
- 项目小经验
- Tomcat 7最大并发连接数的正确修改方法
- 安装python及各种数据包
- 数值计算库gsl(GNU Scientific Library)
- Jquery的详解
- 画图步骤