Open Clear2 opened 4 years ago
// 原地修改数组 func removeDuplicates(nums []int) int { if len(nums) == 0 { return 0 } var i = 0; for j := 1; j < len(nums); j++ { if (nums[j] != nums[i]) { i++ nums[i] = nums[j] } } return i + 1 }
var num1 = []int{0,0,1,1,1,2,2,3,3,4} length := removeDuplicates(num1)