Skip to content

Commit e00c408

Browse files
committed
Create: 0027-Remove-Element.dart
1 parent ff32745 commit e00c408

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

dart/0027-remove-element.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
int removeElement(List<int> nums, int val) {
3+
int i = 0;
4+
int end = nums.length - 1;
5+
while (i <= end) {
6+
if (nums[i] == val) {
7+
int tmp = nums[end];
8+
nums[end] = nums[i];
9+
nums[i] = tmp;
10+
end -= 1;
11+
} else {
12+
i += 1;
13+
}
14+
}
15+
return i;
16+
}
17+
}

0 commit comments

Comments
 (0)