func removeDuplicates(nums []int) int {
if nums == nil {
return 0
}
k := 0
for _, v := range nums {
if v != nums[k] {
k++
nums[k] = v
}
}
return k + 1
}
func removeDuplicates(nums []int) int {
if len(nums) < 2 {
return len(nums)
}
count := 0
for i := 1; i < len(nums); i++ {
if nums[count] != nums[i] {
count++
nums[count] = nums[i]
}
}
return count + 1
}
func removeDuplicates(nums []int) int {
k := 0
for i:=0; i < len(nums)-1; i++ {
if nums[i] == nums[i + 1] {
continue
} else {
k++
temp := nums[i + 1]
nums[k] = temp
}
}
return k + 1
}
func removeDuplicates(nums []int) int {
if len(nums) < 1 {
return len(nums)
}
i := 0
for j := 1; j < len(nums); j++ {
if nums[i] != nums[j] {
nums[i+1] = nums[j]
i++
}
}
return i + 1
}
func removeDuplicates(nums []int) int {
idx := 0
for i:=0;i<len(nums);i++ {
for i+1<len(nums) && nums[i] == nums[i+1] {
i++
}
nums[idx] = nums[i]
idx++
}
return idx
}
func removeDuplicates(nums []int) int {
count := 0
for i, _ := range nums {
if i == 0 {
count++
continue
} else if nums[i] != nums[i-1] {
nums[count] = nums[i]
count++
}
}
return count
}
댓글 영역