Answers for "Go circular rotation of array moving right"

Go
0

Go circular rotation of array moving right

// circular rotation moving to right
func rotateRight(arr[]int, rotate int) []int {
	if rotate == 0 || len(arr) == 0 || len(arr) == 1 {
		return arr
	}
	if len(arr) < rotate {
		rotate = rotate % len(arr)
	}
	lhs := arr[len(arr) - rotate:]
	return append(lhs, arr[:len(arr) - rotate]...)
}
Posted by: Guest on April-26-2021

Browse Popular Code Answers by Language