首页 > 代码库 > 026. Remove Duplicates from Sorted Array

026. Remove Duplicates from Sorted Array

 1 class Solution { 2 public: 3     int removeDuplicates(vector<int>& nums) { 4         if (nums.size() == 0) return 0; 5         int j = 0; 6         for (int i = 1; i < nums.size(); ++i) { 7             if (nums[i] != nums[j]) { 8                 nums[++j] = nums[i]; 9             }10         }11         return j + 1;12     }13 };

 

026. Remove Duplicates from Sorted Array