您的位置:首页 > 其它

26. Remove Duplicates from Sorted Array

2016-07-01 00:00 393 查看
public class RemoveDuplicates {
public int removeDuplicates(int[] nums) {
int nlength = 0;
int tmp = 0;
for(int i = 0; i< nums.length; i++){
if(i >= 1){
if(tmp < nums[i]){
nlength++;
tmp = nums[i];
}
} else {
tmp = nums[i];
nlength++;
}
}
return nlength;
}

public static void main(String[] args) {
RemoveDuplicates rd = new RemoveDuplicates();
System.out.println(rd.removeDuplicates(new int[]{1,1,1}));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: