首页 > 编程语言 > 详细

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

时间:2017-03-08 20:20:26      阅读:196      评论:0      收藏:0      [点我收藏+]

class Solution {
public:
/**
* @param A: a list of integers
* @return : return an integer
*/
int removeDuplicates(vector<int> &nums) {
// write your code here
if(nums.empty())
{
return 0;
}//if

int n = nums.size(),j=0;

for(int i=1;i<n;++i)
{
if(nums[i] != nums[j])
{
nums[++j] = nums[i];
}//if
}//for
nums.resize(j+1);
return j+1;
}
};

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

原文:http://www.cnblogs.com/zhaoshengyun/p/6522811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!