luoheng
10/25/2019 - 1:42 PM

reverseVowels


func isVowels(c byte) bool {
    switch c {
    case 'a','i','o','e','u','A','I','O','E','U':
        return true
    }
    return false
}

func reverseVowels(s string) string {
    res := []byte(s)
    for i, j := 0, len(res)-1; i < j; i++ {
        if isVowels(res[i]) {
            for !isVowels(res[j]) {
                j--
            }
            res[i], res[j] = res[j], res[i]
            j--
        }
    }
    return string(res)
}