80. Remove Duplicates from Sorted Array II
2016-03-21 11:08
375 查看
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array nums =
Your function should return length =
It doesn't matter what you leave beyond the new length.
Subscribe to see which companies asked this question
What if duplicates are allowed at most twice?
For example,
Given sorted array nums =
[1,1,1,2,2,3],
Your function should return length =
5, with the first five elements of nums being
1,
1,
2,
2and
3.
It doesn't matter what you leave beyond the new length.
Subscribe to see which companies asked this question
public class Solution { public int removeDuplicates(int[] nums) { int count = 0; if(nums.length<=1)return nums.length; int slow=0,fast=nums[0]-1; for(int i = 0 ;i<nums.length;i++){ if(fast!=nums[i]){ fast=nums[i]; count = 1; }else{ count++; } if(count<=2){ nums[slow]=fast; slow++; } } return slow; } }
相关文章推荐
- idea_文件级别注释&自定义Live Template类似于sout
- Daum Equation Editor(公式编辑器)
- uiview常用方法
- 怎么把pdf页面转换成图片
- eclipse无法启动的各种解决方法
- 基于python+ffmpeg的视频并发直播压力测试
- Android生成随机数
- linux下Apache服务器配置虚拟域名
- type=image和type=submit的区别
- HTTP Content-type 常用对照表
- php限制文件下载速度代码
- php常用正则表达式
- 最常用的PHP正则表达式收集整理
- 解决PHP超大文件下载,断点续传下载的方法详解
- 【转载】如何防止Session伪造攻击
- 关于PHP中浏览器禁止Cookie后,Session能使用吗?
- 修改dede后台上传文件大小限制
- height:100%和height:auto的区别
- js 如何获得ckeditor的值
- javascript 全局变量,私有变量。