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 };
双指针,压缩重复元素
浙公网安备 33010602011771号