Leetcode Problem 2785. Sort Vowels in a String

2785. Sort Vowels in a String

Leetcode Solutions

Sorting Vowels in a String

  1. Define a helper function isVowel to check if a character is a vowel (case-insensitive).
  2. Iterate through the string s and for each character:
    • If it is a vowel, add it to a list vowels.
    • Otherwise, continue to the next character.
  3. Sort the list vowels based on ASCII values.
  4. Initialize an empty string result to build the final string.
  5. Iterate through the string s again and for each character:
    • If it is a vowel, append the next vowel from the sorted vowels list to result.
    • If it is a consonant, append the consonant to result.
  6. Return the result string.
UML Thumbnail

Counting Sort for 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...