Simple C++ solution


  • 0
    T
    class Solution {
    public:
        int removeElement(vector<int>& nums, int val) {
            int length = 0;
            int n = nums.size();
    
            for (int i = 0; i < n; i++) {
                if (nums[i] != val) {
                    nums[length++] = nums[i];
                }
            }
    
            return length;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.