Skip to content

Commit 25d4d22

Browse files
authored
Update Reverse-Vowels-of-a-String.py
1 parent ec97cba commit 25d4d22

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Leetcode/Reverse-Vowels-of-a-String.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,32 @@ def reverseVowels(self, s):
1717
newstring = ''.join(map(str, container))
1818
return newstring
1919

20+
"""
21+
class Solution:
22+
def reverseVowels(self, s: str) -> str:
23+
if len(s) == 0:
24+
return ""
25+
s = list(s)
26+
vowel_list = {"a", "e", "o", "u", "i", "A", "E", "O", "U", "I"}
27+
28+
left_ptr = 0
29+
right_ptr = len(s) - 1
30+
31+
while left_ptr < right_ptr:
32+
if s[left_ptr] in vowel_list and s[right_ptr] in vowel_list:
33+
temp = s[left_ptr]
34+
s[left_ptr] = s[right_ptr]
35+
s[right_ptr] = temp
36+
right_ptr -= 1
37+
left_ptr += 1
38+
else:
39+
if s[left_ptr] in vowel_list:
40+
right_ptr -= 1
41+
elif s[right_ptr] in vowel_list:
42+
left_ptr += 1
43+
else:
44+
left_ptr += 1
45+
right_ptr -= 1
46+
47+
return "".join(s)
48+
"""

0 commit comments

Comments
 (0)