import unittest

def reverse_vowels(str):
    if not str: return str

    vowels = ['a', 'e', 'i', 'o', 'u']

    list_str = list(str)

    head, tail = 0, len(list_str) - 1

    while head < tail:
        if list_str[head].lower() not in vowels:
            head += 1
        
        elif list_str[tail].lower() not in vowels:
            tail -= 1
        
        else:
            list_str[head], list_str[tail] = list_str[tail], list_str[head]
            head += 1
            tail -= 1
    
    return ''.join(list_str)

print(reverse_vowels('leEtcode'))

class Solution:
    vowels = ['a', 'e', 'i', 'o', 'u']

    def reverse_vowels(self, string):
        if not string:
            return string
        
        string_list = list(string)
        head, tail = 0, len(string) - 1

        while head < tail:
            if string_list[head] not in self.vowels:
                head += 1
            elif string_list[tail] not in self.vowels:
                tail -= 1
            else:
                string_list[head], string_list[tail] = string_list[tail], string_list[head]
                head += 1
                tail -= 1
        
        return ''.join(string_list)
        