Remove Element
Easy
Array
Two Pointers
In-place

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:[[3,2,2,3],3]
Output:2
Explanation: Your function should return k = 2, with the first two elements of nums being 2.
Input:[[0,1,2,2,3,0,4,2],2]
Output:5
Explanation: Your function should return k = 5, with the first five elements containing 0, 0, 1, 3, and 4.

Constraints:

  • 0 ≤ nums.length ≤ 100
  • 0 ≤ nums[i] ≤ 50
  • 0 ≤ val ≤ 100
Code Editor
Loading advanced editor...
Console Output

Ready to execute

Click "Run Code" to see your output here