Description

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.

Examples

Input:nums = [3,2,2,3], val = 3
Output:2
Explanation:

Your function should return k = 2, with the first two elements being 2.

Input:nums = [0,1,2,2,3,0,4,2], val = 2
Output:5
Explanation:

Your function should return k = 5.

Input:nums = [1], val = 1
Output:0
Explanation:

The only element equals val, so all elements are removed, leaving length 0.

Constraints

  • 0 ≤ nums.length ≤ 100
  • 0 ≤ nums[i] ≤ 50
  • 0 ≤ val ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!