Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication7.cpp : 定義主控台應用程式的進入點。
- //
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- using namespace std;
- int removeDuplicates(vector<int>& nums)
- {
- if (nums.size() == 0)
- return 0;
- int ans = 0;
- for (int i = 0; i < nums.size()-1;)
- {
- cout << "***i=" << i << endl;
- if (nums[i] == nums[i + 1])
- {
- ans++;
- nums.erase(nums.begin() + i + 1);
- }
- else
- i++;
- }
- for (int i = 0; i < nums.size(); i++) {
- cout<<nums[i];
- }
- cout << endl;
- return ans;
- }
- int main()
- {
- vector<int> in1 = { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4 },in2(0);
- cout << removeDuplicates(in1) << endl;
- cout << removeDuplicates(in2) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment