0.8
This commit is contained in:
1 parent
d424ed1891
commit
c03132a99d
8 files changed
+308
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package com.hong.www;
|
||||
|
||||
public class A28 {
|
||||
public int removeElement(int[] nums, int val) {
|
||||
int j=nums.length-1;
|
||||
while (j >= 0 && nums[j] == val) {
|
||||
j--;
|
||||
}
|
||||
if(j==0 && nums[0]==val){
|
||||
return 0;
|
||||
}
|
||||
for(int i=0;i<j;i++){
|
||||
if(nums[i]==val){
|
||||
nums[i]=nums[j];
|
||||
nums[j]=val;
|
||||
j--;
|
||||
/* if(j==i){
|
||||
break;
|
||||
} */
|
||||
while (nums[j]==val && j>i) {
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return j+1;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
A28 a28 = new A28();
|
||||
int[] nums = {2};
|
||||
System.out.println(a28.removeElement(nums, 3));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user