Skip to content

Commit 1a64b36

Browse files
committed
refactory the code
1 parent 99c6cf9 commit 1a64b36

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

‎algorithms/cpp/removeElement/removeElement.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313

1414
class Solution {
1515
public:
16+
int removeElement(vector<int>& nums, int val) {
17+
int pos = 0;
18+
for (int i=0; i<nums.size(); i++){
19+
if (nums[i] != val){
20+
nums[pos++] = nums[i];
21+
}
22+
}
23+
return pos;
24+
}
25+
1626
int removeElement(int A[], int n, int elem) {
1727
int tail = n-1;
1828
int i = 0;

0 commit comments

Comments
 (0)