Skip to content

Commit 01cd82a

Browse files
authored
Update Remove Element.java
1 parent a054043 commit 01cd82a

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Easy/Remove Element.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
class Solution {
22
public int removeElement(int[] nums, int val) {
3-
int start = 0;
4-
int end = 0;
5-
int n = nums.length;
6-
while (end < n) {
7-
if (nums[end] != val) {
8-
nums[start++] = nums[end];
3+
int idx = 0;
4+
for (int i = 0; i < nums.length; i++) {
5+
if (nums[i] != val) {
6+
nums[idx++] = nums[i];
97
}
10-
end++;
118
}
12-
return start;
9+
return idx;
1310
}
1411
}

0 commit comments

Comments
 (0)