first init

This commit is contained in:
flowerstonezl
2026-01-29 17:04:05 +08:00
commit e1006fa09c
51 changed files with 4288 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int count = nums.size();
for (int i = 0; i < count; i++)
{
if (nums[i] != val)
{
nums[slow_index] = nums[i];
slow_index++;
}
}
return slow_index;
}
private:
int slow_index = 0;
};
int main()
{
vector<int> nums = {0, 1, 2, 2, 3, 0, 4, 2};
int val = 2;
Solution solution;
int result = solution.removeElement(nums, val);
cout << "The length of nums after removing val is: " << result << endl;
for (int i = 0; i < result; i++)
{
cout << nums[i] << " ";
}
system("pause");
return 0;
}