1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio(false);
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     int removeDuplicates(vector<int>& nums) 
12     {
13         int sz=nums.size();
14         if(sz<2)
15             return sz;
16         int i=0,j=1;
17         while(j<sz)
18         {
19             if(nums[i]!=nums[j])
20                 nums[++i]=nums[j];
21             j++;
22         }
23         return i+1;
24     }
25 };

双指针,压缩重复元素

posted on 2018-04-16 10:47  高数考了59  阅读(78)  评论(0)    收藏  举报