mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-02-27 11:58:39 +08:00
19 lines
268 B
Go
19 lines
268 B
Go
package A
|
|
|
|
func constructTransformedArray(nums []int) []int {
|
|
n := len(nums)
|
|
res := make([]int, n)
|
|
for i, v := range nums {
|
|
if v > 0 {
|
|
res[i] = nums[(i+v)%n]
|
|
}
|
|
if v == 0 {
|
|
res[i] = v
|
|
}
|
|
if v < 0 {
|
|
res[i] = nums[((i+v)%n+n)%n]
|
|
}
|
|
}
|
|
return res
|
|
}
|