Created
December 15, 2022 23:27
-
-
Save abdulrahmanAlotaibi/cfc740f8d325d0cbdba2274b8394c22d to your computer and use it in GitHub Desktop.
Array # 6 : Rotate Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func rotate(nums []int, k int) { | |
l := len(nums) | |
k = k % l | |
newNums := append(nums[l-k:l], nums[0:l-k]...) | |
copy(nums,newNums) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment