remove_duplicate

  • 2022-12-14
  • 浏览 (511)

remove_duplicate.go 源码

package main

//删除排序数组中的重复数据

func removeDuplicates(nums []int) int {
	i, j := 0, 1
	for j < len(nums) {
		if nums[i] == nums[j] {
			j++
		} else {
			nums[i+1] = nums[j]
			i, j = i+1, j+1
		}
	}
	return i + 1
}

你可能感兴趣的文章

best_time_buy_sell_stock

best_time_buy_sell_stock_ii

climb_stairs

0  赞