重拾编程之路--26. Remove Duplicates from Sorted Array
2016-01-19 11:46
387 查看
public class Solution {
public int removeDuplicates(int[] nums) {
if(nums==null){
return 0;
}
if(nums.length==0){
return 0;
}
int len=nums.length;
int pos=1;
for(int i=1;i<len;i++){
if(nums[i]==nums[i-1]){
continue;
}else{
nums[pos]=nums[i];
pos++;
}
}
return pos;
}
}
public int removeDuplicates(int[] nums) {
if(nums==null){
return 0;
}
if(nums.length==0){
return 0;
}
int len=nums.length;
int pos=1;
for(int i=1;i<len;i++){
if(nums[i]==nums[i-1]){
continue;
}else{
nums[pos]=nums[i];
pos++;
}
}
return pos;
}
}
相关文章推荐
- SpringMVC Controller 返回值的可选类型
- Yii2 AssetManage linkAssets
- C++11标准库 - array
- openswan klips代码分析--(1)初始化流程
- python 协程
- Python序列之列表 (list)
- c++ 设计模式1
- java读写文件及保留指定位小数
- Eclipse优化集合,Eclipse优化速度,解决Ctrl+C、Ctrl+V卡
- 自学Python八 爬虫大坑之网页乱码
- CodeForces 385A Bear and Raspberry
- 用 Webgoat 撬动地球,看安全测试的引路石!
- 抖动代码
- java 设计模式学习
- 【C语言天天练(十五)】字符串输入函数fgets、gets和scanf
- java并发
- 《python》学习笔记(Day2),读入磁盘文件,经过处理,保存成相应的磁盘文件
- CUDA编程——Mars:MapReduce on GPU
- MCMC and faster Gibbs Sampling using Rcpp
- C++中变量,函数的作用域和生命周期?