Skip to content
Veltoryx Technologies
ProProblem 7● EasyLeetCode #27 ↗2 min readUpdated 30 October 2026

Remove Element

Remove every copy of a value in place and return how many values are left, using a write pointer.

01The problem

Remove every occurrence of val from nums in place. Return k, the number of values left; the first k slots must hold them (in any order). What's after slot k − 1 doesn't matter.

InputOutputFirst k slots
nums = [3, 2, 2, 3], val = 32[2, 2]
nums = [0,1,2,2,3,0,4,2], val = 25[0, 1, 3, 0, 4]

Loading the rest of the lesson…