Sobes.tech
Senior

Given an array slice of integers. Write a function remove that deletes all zeros Examples: remove([]) -> [] remove([0]) -> [] remove([1,0,0,2]) -> [1,2]

sobes.tech AI

Answer from AI

go func remove(nums []int) []int { result := make([]int, 0, len(nums)) for _, num := range nums { if num != 0 { result = append(result, num) } } return result }

The function creates a new slice and adds only the non-zero elements of the original slice.