Skip to content

Commit

Permalink
Create: 0027-Remove-Element.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
laitooo committed Jan 8, 2023
1 parent ff32745 commit e00c408
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dart/0027-remove-element.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
int removeElement(List<int> nums, int val) {
int i = 0;
int end = nums.length - 1;
while (i <= end) {
if (nums[i] == val) {
int tmp = nums[end];
nums[end] = nums[i];
nums[i] = tmp;
end -= 1;
} else {
i += 1;
}
}
return i;
}
}

0 comments on commit e00c408

Please sign in to comment.