标签:
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".
编写函数输入一个字符串,将其中的元音字母逆置。
class Solution { public: string reverseVowels(string s) { int left=0; int right=s.size()-1; string t="aeiouAEIOU"; while(left<right) { if(t.find(s[left])==string::npos) { ++left; } else if(t.find(s[right])==string::npos) { --right; } else { swap(s[left++],s[right--]); } } return s; } };
345. Reverse Vowels of a String(C++)
标签:
原文地址:http://www.cnblogs.com/19q3/p/5493046.html