luoheng
10/26/2019 - 8:04 AM

reverseStr

func reverseStr(s string, k int) string {
    res := []byte(s)
    for i := 0; i < len(res); i += 2*k {
        s, e := i, 0
        if len(res) - i >= k {
            e = k + i - 1
        } else {
            e = len(res)-1
        }
        for ; s < e; s, e = s + 1, e - 1 {
            res[s], res[e] = res[e], res[s]
        }
    }
    return string(res)
}