首页 > 代码库 > 027. Remove Element

027. Remove Element

 1 class Solution { 2 public: 3     int removeElement(vector<int>& nums, int val) { 4         if (nums.size() == 0) return 0; 5         else { 6             int index = 0; 7             for (int i = 0; i < nums.size(); ++i) { 8                 if (nums[i] != val) { 9                     nums[index++] = nums[i];10                 }11             }12             return index;13         }14     }15 };

 

027. Remove Element