1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// @Title: 反转字符串中的元音字母 (Reverse Vowels of a String)
// @Author: 15816537946@163.com
// @Date: 2020-06-25 07:15:36
// @Runtime: 4 ms
// @Memory: 4.1 MB
func reverseVowels(s string) string {
	bytes := []byte(s)
	lo, hi := 0, len(bytes)-1
	for lo<hi {
		if !isVowels(bytes[lo]) {
			lo++
		}
		if !isVowels(bytes[hi]) {
			hi--
		}
		if isVowels(bytes[hi]) && isVowels(bytes[lo]) {
		bytes[lo], bytes[hi] = bytes[hi],bytes[lo]
		lo++
		hi--
		}
	}
	return string(bytes)
}

func isVowels(b byte) bool {
	if b == 'a' || b =='e' || b== 'i' || b =='o' || b == 'u' || b == 'A' || b == 'E' || b == 'I' || b=='O' || b == 'U'{ 
		return true
	}
	return false
}