题目:https://leetcode-cn.com/problems/remove-element/
答案:暴力法:
public int removeElement(int[] nums, int val) {
int count = 0,tmp;
boolean isExit = false;
for(int i=0;i<nums.length-count;i++){
if(nums[i] == val){
isExit = false;
while (nums.length-1-count>i){
if(nums[nums.length-1-count]==val){
count++;
}else{
isExit = true;
break;
}
}
if(isExit){
tmp = nums[nums.length-1-count];
nums[nums.length-1-count] = nums[i];
nums[i] = tmp;
}
count++;
}
}
return nums.length-count;
}