首页 > 其他 > 详细

345. Reverse Vowels of a String

时间:2020-04-08 00:01:12      阅读:74      评论:0      收藏:0      [点我收藏+]

Problem:

Write a function that takes a string as input and reverse only the vowels of a string.

Example 1:

Input: "hello"
Output: "holle"

Example 2:

Input: "leetcode"
Output: "leotcede"

Note:
The vowels does not include the letter "y".

思路

Solution (C++):

string reverseVowels(string s) {
    int i = 0, j = s.length()-1;
    while (i < j) {
        i = s.find_first_of("aeiouAEIOU", i);
        j = s.find_last_of("aeiouAEIOU", j);
        if (i < j)  swap(s[i++], s[j--]);
    }
    return s;
}

性能

Runtime: 12 ms??Memory Usage: 8.1 MB

思路

Solution (C++):


性能

Runtime: ms??Memory Usage: MB

345. Reverse Vowels of a String

原文:https://www.cnblogs.com/dysjtu1995/p/12657008.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!