Created
November 22, 2020 07:49
-
-
Save 2hanX/1a4f27a9181a8c46f29918b50c7a99a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/solution/ | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class Solution | |
{ | |
public: | |
int removeDuplicates(vector<int>& nums) | |
{ | |
if(nums.size() == 0) return 0; | |
int i=0; | |
for (int j = 1; j < nums.size(); j++) | |
{ | |
if (nums[j] != nums[i]) | |
{ | |
i++; | |
nums[i] = nums[j]; | |
} | |
} | |
return i+1; | |
} | |
}; | |
int main(int argc, char const *argv[]) | |
{ | |
Solution s; | |
vector<int> nums; | |
nums.push_back(1); | |
nums.push_back(1); | |
nums.push_back(2); | |
nums.push_back(2); | |
nums.push_back(3); | |
printf("%d\n",s.removeDuplicates(nums)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment