LeetCode-Remove Duplicates From Sorted Array

descriptions:

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.

注意是有序数组。。

代码:

if(nums.length==0) return 0;

int flag=1;

for(int i=1;i<nums.length;i++){

if(nums[i-1]==nums[i]) 

{

continue;

}else{

nums[flag]=nums[i];

flag++;

}

}

return flag;

posted @ 2015-06-15 20:10  hhrrrr  阅读(122)  评论(0)    收藏  举报