Skip to content

Instantly share code, notes, and snippets.

@yshuman1
Created March 13, 2019 07:49
Show Gist options
  • Save yshuman1/fbe66012845fcb9681673e48e927070b to your computer and use it in GitHub Desktop.
Save yshuman1/fbe66012845fcb9681673e48e927070b to your computer and use it in GitHub Desktop.
func reverse(bytes []byte) {
i, j := 0, len(bytes)-1
for i < j {
bytes[i], bytes[j] = bytes[j], bytes[i]
i++
j--
}
}
func min(a,b int)int{
if a < b {
return a
}
return b
}
func reverseStr(s string, k int) string {
bytes := []byte(s)
for i:=0; i <len(bytes); i +=2*k{
j:= min(int(i+k), len(s))
reverse(bytes[i:j])
}
return string(bytes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment