leetCode345.ReverseVowelsofaString字符串
345. Reverse Vowels of a String

创新互联是专业的湘东网站建设公司,湘东接单;提供网站设计、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行湘东网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
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".
思路:
找到元音字母,标记位置,进行置换。
代码如下:
// vowels(元音字母)包括:a,e,i,o,u.
class Solution {
public:
bool isVowels(char c)
{
char vowels[10] = {'a','e','i','o','u','A','E','I','O','U'};
for(int i = 0; i < 10; i++)
{
if(c == vowels[i])
{
return true;
break;//return 和 break在一起都有反应么?
}
}
return false;
}
string reverseVowels(string s) {
vector recordIndex;
vector str;
for(int i = 0;i2016-08-08 10:52:10
当前标题:leetCode345.ReverseVowelsofaString字符串
当前地址:http://www.jxjierui.cn/article/ijohee.html


咨询
建站咨询
