Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
My Solution

Thai Minh

Jul 24, 2023

class Solution:   def reverseVowels(self, s: str) -> str:     # TODO: Write your code here     vowels_arr = ['a', 'e', 'u', 'o', 'i']     # front and back pointers     # travel until they are both vowel then swap     f_ptr, b_ptr = 0, len(s) - 1     str_list = list(s)     while f_ptr < b_ptr:       while str_list[f_ptr].lower() not in vowels_arr and f_ptr < b_ptr:         f_ptr += 1       while str_list[b_ptr].lower() not in vowels_arr and b_ptr > f_ptr:         b_ptr -= 1       str_list[f_ptr], str_list[b_ptr] = str_list[b_ptr], str_list[f_ptr]       f_ptr += 1       b_ptr -= 1     return "".join(str_list)

0

0

Comments
Comments