一.移动零 解法一:模拟 func moveZeroes(nums []int) {n:=len(nums)l,r:=0,1for r<n&&l<n{if nums[r]==0{if nums[l]!=0{l++r++}else{r++}}else if nums[l]==0{nums[l],nums[r]=nums[r],nums[l]l++r++}else{l++r++}} } 二.双指针 func moveZeroes(nums []int) {n:=len(nums)j:=0for i:=0;i<n;i++{if nums[i]!=0{nums[j]=nums[i]j+=1}}for i:=j;i<n;i++{nums[i]=0} } 二.有序数组的平方 解法一:暴力排序 func sortedSquares(nums []int) []int {n:=len(nums)for i:=0;i<n;i++{nums[i]=nums[i]*nums[i]}sort.Ints(nums)return nums } 解法二:双指针 func sortedSquares(nums []int) []int {n:=len(nums)k:=n-1res:=make([]int,n)l,r:=0,n-1for l<=r{if nums[l]+nums[r]<0{res[k]=nums[l]*nums[l]k-=1l++}else{res[k]=nums[r]*nums[r]k-=1r--}}return res }