-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
33 lines (31 loc) · 812 Bytes
/
Copy pathsolution.java
File metadata and controls
33 lines (31 loc) · 812 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
// 27. Remove Element
// https://leetcode.com/problems/remove-element/
// Easy | Java | Accepted 2025-10-02
// Runtime 0 ms | Memory 41.9 MB
class Solution {
public int removeElement(int[] nums, int val) {
int[] arr = new int[nums.length];
for(int i = 0; i<nums.length; i++)
{
arr[i] = nums[i];
}
int start = 0;
int count = 0;
int numsI = 0;
while(start<nums.length)
{
while(start<nums.length&& arr[start]==val){
start++;
count++;
}
if(start>=nums.length)
{
break;
}
nums[numsI] = arr[start];
numsI++;
start++;
}
return nums.length - count;
}
}