class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int len = nums.size();
int i=0,j=0;
while(j<len){
if(nums[j]!=val){
nums[i]=nums[j];
i++;
}
j++;
}
return i;
}
};
class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
i = 0
for j in range(0,len(nums)):
if nums[j]!=val:
nums[i]=nums[j]
i+=1
return i
27. 移除元素 - 移除元素-力扣
最新推荐文章于 2024-11-05 17:16:24 发布