Created
April 4, 2019 06:19
-
-
Save Ahmah2009/8c3fd949e8a7ae7f3639d160f146b747 to your computer and use it in GitHub Desktop.
345. Reverse Vowels of a String leetCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reverseVowels(s string) string { | |
//A, E, I, O, and U | |
vowlesMap := map[byte]bool{ | |
'a':true,'A':true, | |
'e': true,'E':true, | |
'i':true,'I':true, | |
'o':true,'O':true, | |
'u':true,'U':true} | |
vowlesValues := []byte{} | |
n:= 0 | |
for i:=range s{ | |
if vowlesMap[s[i]]{ | |
vowlesValues = append(vowlesValues, s[i]) | |
n++ | |
} | |
} | |
n-- | |
s1 := make([]byte, len(s)) | |
for i:= range s1{ | |
if vowlesMap[s[i]]{ | |
s1[i] = vowlesValues[n] | |
n-- | |
}else{ | |
s1[i]=s[i] | |
} | |
} | |
return string(s1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment