Skip to content

Commit 20e13de

Browse files
authored
Create RemoveElement.java
1 parent c60d4a3 commit 20e13de

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

RemoveElement.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
class Solution {
4+
public int removeElement(int[] nums, int val) {
5+
6+
/*
7+
link : https://leetcode.com/problems/remove-element/
8+
Algorithm :
9+
in this case we have to overwrite only those element in array which is not equal to given value;
10+
and this will print upto only those indexes which we have return
11+
*/
12+
int j=0;
13+
for(int i=0;i<nums.length;i++){
14+
if(nums[i]!=val)
15+
nums[j++]=nums[i];
16+
}
17+
return j;
18+
}
19+
}

0 commit comments

Comments
 (0)