27. Remove Element

 class Solution {

public:

    int removeElement(vector<int>& nums, int val) {

        int current = 0;

        for (int i = 0; i < nums.size(); i++)

        {

            if (nums[i] != val){

                nums[current] = nums[i];

                current++;

            }

        }

        return current;

    }

};

Comments

Popular posts from this blog

1431. Kids With the Greatest Number of Candies

125. Valid Palindrome

771. Jewels and Stones