您的位置:首页 > 其它

Lintcode落单的数 删除排序数组中的重复数字 II

2017-08-01 16:58 525 查看
落单的数

http://www.wengweitao.com/lintcode-single-number-i-ii-iii-luo-dan-de-shu.html

删除排序数组中的重复数字 II

class Solution {
public:
/**
* @param A: a list of integers
* @return : return an integer
*/
int removeDuplicates(vector<int> &nums) {
// write your code here
int i = 0;
int count = 1;
if (nums.size() == 0)
return 0;
for (int j = 1; j < nums.size(); ++j) {
if (nums[i] == nums[j] && count < 2) {
++count;
nums[++i] = nums[j];
} else if (nums[i] != nums[j]) {
count = 1;
nums[++i] = nums[j] ;
}
}
return i+1;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: