"""Leetcode 345. Reverse Vowels of a String
Easy

URL: https://leetcode.com/problems/reverse-vowels-of-a-string/

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".
"""

class Solution(object):
    def reverseVowels(self, s):
        """
        :type s: str
        :rtype: str
        """
        pass


def main():
    pass


if __name__ == '__main__':
    main()

@@ -356,16 +356,36 @@
 Solution
+ReversedVowelPosDict
 (object)
@@ -475,55 +475,1239 @@
 str%0A
-        %22%22%22%0A        pass%0A%0A%0Adef main():%0A    pass
+%0A        Time complexity: O(n).%0A        Space complexity: O(n).%0A        %22%22%22%0A        if not s:%0A            return ''%0A%0A        n = len(s)%0A%0A        # Use set to collect vowels for quick lookup.%0A        vowels = set(%5B'A', 'E', 'I', 'O', 'U',%0A                      'a', 'e', 'i', 'o', 'u'%5D)%0A%0A        # Collect vowles & positions in a dict: pos-%3Evowel, in reversed order.%0A        vowel_chars = %5B%5D%0A        vowel_pos = %5B%5D%0A        for pos, c in enumerate(s):%0A            if c in vowels:%0A                vowel_chars.append(c)%0A                vowel_pos.append(pos)%0A%0A        rev_vowel_pos = dict()%0A        for i, c in enumerate(reversed(vowel_chars)):%0A            rev_vowel_pos%5Bvowel_pos%5Bi%5D%5D = c%0A%0A        # Iterate through string list, replace vowel by dict: pos-vowel.%0A        s_list = list(s)%0A        for i in range(n):%0A            if i in rev_vowel_pos:%0A                s_list%5Bi%5D = rev_vowel_pos%5Bi%5D%0A%0A        return ''.join(s_list)%0A%0A%0Adef main():%0A    # Output: %22holle%22%0A    s = %22hello%22%0A    print SolutionReversedVowelPosDict().reverseVowels(s)%0A%0A    # Output: %22leotcede%22%0A    s = %22leetcode%22%0A    print SolutionReversedVowelPosDict().reverseVowels(s)%0A%0A    # Output: %22epplA%22%0A    s = %22Apple%22%0A    print SolutionReversedVowelPosDict().reverseVowels(s)
 %0A%0A%0Ai

Complete reversed vowel pos sol