@requires_authorization
@author johnsondu
@create_time 2015.7.22 18:58
@url [remove dublicates from sorted array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)
/**
* @description: 从有序数组中剔除元素,最多常量额外空间,设置标兵依次比較
* @time_complexity: O(n)
* @space_complexity: O(1)
*/
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
const int len = nums.size();
if(len < 2) return len;
int first = nums[0];
int idx = 1;
for(int i = 1; i < len; i ++) {
if(nums[i] == first) continue;
else {
first = nums[i];
nums[idx] = first;
idx ++;
}
}
return idx;
}
};

【leetcode】 26. Remove Duplicates from Sorted Array的更多相关文章

  1. 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...

  2. 【LeetCode】26. Remove Duplicates from Sorted Array

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  3. 【LeetCode】80. Remove Duplicates from Sorted Array II (2 solutions)

    Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...

  4. 【LeetCode】080. Remove Duplicates from Sorted Array II

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...

  5. 【一天一道LeetCode】#26. Remove Duplicates from Sorted Array

    一天一道LeetCode系列 (一)题目 Given a sorted array, remove the duplicates in place such that each element app ...

  6. 【LeetCode】80. Remove Duplicates from Sorted Array II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  7. 【LeetCode】83 - Remove Duplicates from Sorted Array

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  8. 【LeetCode】026. Remove Duplicates from Sorted Array

    题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  9. 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...

随机推荐

  1. restful规范和drf模块

    restfu1规范 它是一个规范,面向资源架构 10条规范: 1.api与用户的通信协议,总是使用https协议 api网上提供的接口 2.域名: 尽量将api部署在专用域名(会存在跨域问题) API ...

  2. Django中模板查找路径配置

  3. LCD驱动分析(二)帧缓冲设备作为平台设备

    参考:S3C2440 LCD驱动(FrameBuffer)实例开发<一>   S3C2440 LCD驱动(FrameBuffer)实例开发<二> 1.平台设备注册 1.1在li ...

  4. 【HIHOCODER 1067】最近公共祖先·二(LCA)

    描述 上上回说到,小Hi和小Ho用非常拙劣--或者说粗糙的手段山寨出了一个神奇的网站,这个网站可以计算出某两个人的所有共同祖先中辈分最低的一个是谁.远在美国的他们利用了一些奇妙的技术获得了国内许多人的 ...

  5. H.264 Profile-level-id

    基于SIP协议的VOIP通信,该字段通常位于视频协商sdp报文中,如: video RTP/AVP rtpmap: H264/ fmtp: profile-level-id=42801E; packe ...

  6. awk中next以及getline用法示例

    在awk中,如果调用next,那么next之后的命令就都不执行了.此行文本的处理到此结束,开始读取下一条记录并操作. 实例如下: [plain] view plain copy zoer@ubuntu ...

  7. opacity--css + javascript兼容性代码

    css设置opacity 之前看了别人写了一段关于opacity的css代码,没深入理解就copy过来自己用了一段时间,现在重新拿出来又深入研究了一下. .cla{ /* IE 8 */ -ms-fi ...

  8. Working out (DP)

    Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...

  9. HDU-5319 Painter,深搜标记!

    Painter 题意:有一个棋盘n行,列数不超过50,用red和blue给这个棋盘涂色,每个格子每种颜色最多涂一次,如果两种颜色都涂了则该格子颜色为Green;red以斜杠'\'方式涂色,bule以' ...

  10. 如何部署 sources and javadoc jars

    mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file -Durl=file:///home/me/m2-repo \ - ...