Leetcode no. 80
2016-04-08 10:48
429 查看
80. Remove Duplicates from Sorted Array II
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.
Follow up for "Remove Duplicates":
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.
public class Solution { public int removeDuplicates(int[] nums) { int i = 0; for (int n : nums) if (i < 2 || n > nums[i-2]) nums[i++] = n; return i; } }
相关文章推荐
- 如何从网络上获取图片转换成字节流或者保存到本地
- 日记——!
- 在代码修改textview的Drawable 和 使用webview 加载网页
- 【BZOJ 3037】 创世纪 树形DP
- C盘不能新建文件的问题解决办法
- Oracle数据库常用技术
- MPlayer-2016-bin-noConsole
- 可行性分析报告
- CentOS 6.6升级GCC
- interactivePopGestureRecognizer返回时消息传递
- HashMap源码注解 之 常量定义(一)
- App应用之启动界面SplashActivity
- C++一次实验
- Sencha Touch下拉刷新、上拉自动加载
- Android中applicationId与package name的区别
- STL迭代器------Traits编程技法详细理解(一)
- Linux ps --显示当前正在运行的进程列表 2013年7月4日
- ABAP常用函数
- (好)C++ 对象的内存布局(下)
- RecyclerView