题目描述: 代码(C语言):
int removeElement(int* nums
, int numsSize
, int val
){
if(numsSize
== 0){
return 0;
}
int count
= 0;
for(int i
= 0; i
< numsSize
;i
++){
if(nums
[i
] != val
){
nums
[count
] = nums
[i
];
count
++;
}
}
return count
;
}
结果:
代码(java实现):
class Solution {
public int removeElement(int[] nums
, int val
) {
int count
= 0;
for(int i
= 0;i
< nums
.length
;i
++){
if(nums
[i
] != val
){
nums
[count
] = nums
[i
];
count
++;
}
}
return count
;
}
}
结果:
转载请注明原文地址:https://blackberry.8miu.com/read-253.html