Skip to content

Commit 1fa83c2

Browse files
authored
添加(0189.轮转数组.md):增加go版本
1 parent 9dbc514 commit 1fa83c2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

problems/0189.旋转数组.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ class Solution:
124124
## Go
125125

126126
```go
127+
func rotate(nums []int, k int) {
128+
l:=len(nums)
129+
index:=l-k%l
130+
reverse(nums)
131+
reverse(nums[:l-index])
132+
reverse(nums[l-index:])
133+
}
134+
func reverse(nums []int){
135+
l:=len(nums)
136+
for i:=0;i<l/2;i++{
137+
nums[i],nums[l-1-i]=nums[l-1-i],nums[i]
138+
}
139+
}
127140
```
128141

129142
## JavaScript

0 commit comments

Comments
 (0)