From e95b6da176f4841b8d2e703749069ef687bdcddc Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Wed, 10 Sep 2025 20:57:33 -0400 Subject: [PATCH] Time: 1259 ms (24.84%), Space: 22.2 MB (7.19%) - LeetHub --- .../2785-sort-vowels-in-a-string.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py diff --git a/2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py b/2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py new file mode 100644 index 0000000..a620d95 --- /dev/null +++ b/2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py @@ -0,0 +1,29 @@ +class Solution(object): + def sortVowels(self, s): + """ + :type s: str + :rtype: str + """ + ALL_VOWELS = set(['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u']) + + indices = [] + vowels = [] + + for i, letter in enumerate(s): + if letter in ALL_VOWELS: + indices += [i] + vowels += [letter] + + vowels.sort(key=ord) + + newStr = "" + j = 0 + + for i, letter in enumerate(s): + if letter in ALL_VOWELS: + newStr += vowels[j] + j += 1 + else: + newStr += s[i] + + return newStr