-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27.java
More file actions
33 lines (29 loc) · 839 Bytes
/
Copy path27.java
File metadata and controls
33 lines (29 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Solution {
public int removeElement(int[] nums, int val) {
int i;
int count = 0;
int cursor = 0;
for (i = 0;i < nums.length;i++) {
while(cursor < nums.length && nums[cursor] == val) {
if (cursor == nums.length - 1) {
break;
}
cursor++;
}
if (cursor == nums.length - 1 && nums[cursor] == val) {
break;
}
nums[i] = nums[cursor];
count++;
if (cursor == nums.length - 1) {
break;
}
cursor++;
}
return count;
}
public static void main(String[] args){
int[] array = new int[] {3};
System.out.println(new Test().removeElement(array, 3));
}
}