bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 345. Reverse Vowels of a String

345. Reverse Vowels of a String

Leetcode Solutions

Two Pointers Approach to Reverse Vowels in a String

  1. Initialize two pointers, left at the start of the string (index 0) and right at the end of the string (index len(s) - 1).
  2. While left is less than right: a. Increment left until s[left] is a vowel. b. Decrement right until s[right] is a vowel. c. If both s[left] and s[right] are vowels, swap them. d. Increment left and decrement right.
  3. Return the modified string.
UML Thumbnail

Using a Stack to Reverse Vowels in a String

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...