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 };
时间: 2024-10-27 08:23:02