Skip to content

Instantly share code, notes, and snippets.

@Ahmah2009
Created April 4, 2019 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahmah2009/8c3fd949e8a7ae7f3639d160f146b747 to your computer and use it in GitHub Desktop.
Save Ahmah2009/8c3fd949e8a7ae7f3639d160f146b747 to your computer and use it in GitHub Desktop.
345. Reverse Vowels of a String leetCode
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