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

141. Linked List Cycle

67. Add Binary

88. Merge Sorted Array