You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
305 B
18 lines
305 B
package removeelement
|
|
|
|
func removeElement(nums []int, val int) int {
|
|
size := len(nums)
|
|
|
|
for i := len(nums) - 1; i >= 0; i-- {
|
|
if nums[i] == val {
|
|
size -= 1
|
|
nums[i], nums[size] = nums[size], nums[i]
|
|
}
|
|
}
|
|
return size
|
|
}
|
|
|
|
func Remove(nums []int, val int) int {
|
|
return removeElement(nums, val)
|
|
}
|