int removeElement(vector<int>& nums, int val) {
int lgt=0;
for (int i = 0; i < nums.size(); i++)
{
if (nums[i]==val)
{
lgt++;
nums.erase(nums.begin()+i--);
}
}
return nums.size()-lgt;
}

instead returning "num.size() - lgt" you should return "len - lgt" where len is the initial size of vector.
as you are returning num.size() - lgt it is wrong .