Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 67c53e6

Browse files
Create Remove Element from Array .java
1 parent 813d5f8 commit 67c53e6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎Array/Remove Element from Array .java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Remove Element
3+
4+
Given an array and a value, remove all the instances of that value in the array.
5+
Also return the number of elements left in the array after the operation.
6+
It does not matter what is left beyond the expected length.
7+
8+
Example:
9+
If array A is [4, 1, 1, 2, 1, 3]
10+
and value elem is 1,
11+
then new length is 3, and A is now [4, 2, 3]
12+
Try to do it in less than linear additional space complexity.
13+
*/
14+
15+
public class Solution {
16+
public int removeElement(ArrayList<Integer> a, int b) {
17+
a.removeAll(Arrays.asList(b));
18+
return a.size();
19+
}
20+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /