📌  相关文章
📜  go reverse array - Go 编程语言代码示例

📅  最后修改于: 2022-03-11 14:45:02.108000             🧑  作者: Mango

代码示例1
import "fmt"

func reverse(a []int) ([]int) {
    for left, right := 0, len(a)-1; left < right; left, right = left+1, right-1 {
        a[left], a[right] = a[right], a[left]
    }
    return a
}

func main() {
   fmt.Printf("Reversed = %d", reverse([]int{1,2,3,4}))
}