80. Remove Duplicates from Sorted Array II (Array)
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, 2 and 3. It doesn't matter what you leave beyond the new length.
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n = nums.size();
if(n<=) return n;
int p = ;
for (int i = ; i< n; i++)
{
if(nums[i]>nums[p-])
{
nums[p++] = nums[i];
}
}
return p;
}
};
80. Remove Duplicates from Sorted Array II (Array)的更多相关文章
- LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>
LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...
- 80 remove duplicates from sorted array 2
| 分类 leetcode | Follow up for "Remove Duplicates": What if duplicates are allowed at most ...
- leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)
203题是在链表中删除一个固定的值,83题是在链表中删除重复的数值,但要保留一个:82也是删除重复的数值,但重复的都删除,不保留. 比如[1.2.2.3],83题要求的结果是[1.2.3],82题要求 ...
- Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- 48. Remove Duplicates from Sorted List && Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that each ...
- 【LeetCode练习题】Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- LeetCode之“链表”:Remove Duplicates from Sorted List && Remove Duplicates from Sorted List II
1. Remove Duplicates from Sorted List 题目链接 题目要求: Given a sorted linked list, delete all duplicates s ...
- Leetcode: Remove Duplicates from Sorted List II 解题报告
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- 82. Remove Duplicates from Sorted List II && i
题目 83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such tha ...
- 82. Remove Duplicates from Sorted List II【Medium】
82. Remove Duplicates from Sorted List II[Medium] Given a sorted linked list, delete all nodes that ...
随机推荐
- git忽略已经提交的文件【转载】
有时候我们添加.gitignore文件之前已经提交过了文件..gitignore只能忽略那些原来没有被track的文件(自添加以后,从未 add 及 commit 过的文件),如果某些文件已经被纳入了 ...
- emacs之配置etags-select
etags-select比自带的etags定位的更好 ~/emacsConfig/etags-select-setting.el (require 'etags-select) (global-set ...
- String与StringBuffer效率的比较
String str = “”; for (int i=0; i<100; i++) str += “a”; 可是你知道在内存中会产生多少的垃圾出来吗?总共会有a.aa.aaa. aaa….,无 ...
- SAE部署Django1.6+MySQL
[解决]SAE部署Django1.6+MySQL 终于可以舒口气了,今天大部分时间都在搞这个,很是蛋疼,网上资料良莠不齐,我不信这个之前没人做过,但是他们确实分享的不够好. 废话不多说,还是记录一下今 ...
- windows10 vs2015编译 带nginx-rtmp-module 模块的32位nginx
1 下载必要软件 从 http://xhmikosr.1f0.de/tools/msys/下载msys:http://xhmikosr.1f0.de/tools/msys/MSYS_MinGW-w6 ...
- 阻塞队列之五:LinkedBlockingQueue
一.LinkedBlockingQueue简介 LinkedBlockingQueue是一个使用链表完成队列操作的阻塞队列.链表是单向链表,而不是双向链表.采用对于的next构成链表的方式来存储对象. ...
- [转][Java]Jsp入门
<% response.getOutputStream().write("123".getBytes()); %> 新建一个 Web Project 项目,jsp 文件 ...
- 竖屏拍照,但是sd卡中却是横屏解决方法
protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (resultCode) ...
- HDU5336题解
解题思路 这题思路并不难,主要问题是,不太好编码实现(可能是本人练习不够吧),因为有个时间在里面,而且每个小水滴都同时流动,感觉好复杂的样子.比赛时,我首先想到的是DFS+时间流做参数,由于比赛时神经 ...
- MySQL 概念
MySQL 数据库:数据库是一个存储数据的仓库, 用在哪些领域:金融机构.游戏网站.购物网站.论坛网站 提供数据服务的软件 1.软件分类:MySQL.SQL_Server.Oracle.Mariadb ...