删除相同数字
1 class Solution { 2 public: 3 int removeDuplicates(vector<int>& nums) { 4 int count = 0; 5 if (nums.size() == 1) 6 { 7 return nums.size() - count; 8 } 9 for (int i = 1; i < nums.size(); ++i) 10 { 11 if (nums[i] == nums[i-1]) 12 { 13 ++count; 14 } 15 else 16 { 17 if (count) 18 { 19 nums[i-count] = nums[i]; 20 } 21 } 22 } 23 return nums.size() - count; 24 } 25 };
leetCode #26 Remove Duplicates from Sorted Array
原文:http://www.cnblogs.com/xiaoyajiang/p/7835368.html