Algorithms—27.Remove Element

来源:互联网 发布:定时自动打电话软件 编辑:程序博客网 时间:2024/06/05 18:40
public class Solution {
    public int removeElement(int[] nums, int val) {
       int end=nums.length;
int k=0;
for (int i = 0; i < end; i++) {
if (nums[i]==val) {
for (int j = i; j < end-1; j++) {
k=nums[j];
nums[j]=nums[j+1];
nums[j+1]=k;
}
end--;
i--;
}
}
return end;
    }
}
0 0
原创粉丝点击