Download 10-week-algorithm-excercise-master/Week_01/189/rotate_array2.go from Dorothydu/gitrepo_20: direct link, hf CLI and curl.
- Browser
- Download file 283 Bytes
-
https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/Week_01/189/rotate_array2.go
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_20/10-week-algorithm-excercise-master/Week_01/189/rotate_array2.go
-
curl -L -o rotate_array2.go https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/Week_01/189/rotate_array2.go
283 Bytes
| package main | |
| func rotate(nums []int, k int) { | |
| n := len(nums) | |
| k = k % n | |
| reverse(nums, 0, n-1) | |
| reverse(nums, 0, k-1) | |
| reverse(nums, k, n-1) | |
| } | |
| func reverse(nums []int, start, end int) { | |
| for start < end { | |
| nums[start], nums[end] = nums[end], nums[start] | |
| start++ | |
| end-- | |
| } | |
| } | |