-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path26.cpp
32 lines (32 loc) · 881 Bytes
/
26.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
//vector<int>::iterator it=nums.begin();
//vector<int>::iterator end=nums.end();
int tmp,index=0,same=0,move=0,it=0,end=nums.size();
while(it!=end){
tmp=nums[it];
it++;
while(it!=end){
move++;
if(nums[it]==tmp){
same++;
it++;
}else{
if(index<same){
nums[index+1]=nums[it];
same=move;
}else{
same++;
}
index++;
break;
}
}
}
//if(index!=nums.size()){
// nums.resize(index+1);
//}
return end==0?0:index+1;
}
};