26. Remove Element

EasyArray

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. Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to change the array nums such that the first k elements of nums contain the elements which are not equal to val.

Examples

Input: [3,2,2,3] 3

Output: [2,2]

Explanation: Removing all 3s leaves [2,2] (k=2).

Constraints

  • 0 <= nums.length <= 100
  • 0 <= nums[i] <= 50
  • 0 <= val <= 100
Loading...

Run checks all cases above. Submit evaluates all test cases.