LeetCode Problem: Remove Element

Problem statement:

You are given an integer arrays nums and an integer val. The task is to remove all instances of val in the array nums (in-place).

Then return the number of elements which are not equal to val

Example:

Input:

nums1 = [3,2,2,3], val = 3

Expected output:

nums1 = [2,2,_,_]

If you would like to solve the problem on Leetcode, here is the link to the problem: https://leetcode.com/problems/remove-element

Golang Solution:
func removeElement(nums []int, val int) int {
    j := 0
    for i := 0; i < len(nums); i++ {
        if nums[i] != val {
            nums[j] = nums[i]
            j += 1
        }
    }
    return j
}