【leetcode】 26. Remove Duplicates from Sorted Array
@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的更多相关文章
- 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...
- 【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 ...
- 【LeetCode】80. Remove Duplicates from Sorted Array II (2 solutions)
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
- 【LeetCode】080. Remove Duplicates from Sorted Array II
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
- 【一天一道LeetCode】#26. Remove Duplicates from Sorted Array
一天一道LeetCode系列 (一)题目 Given a sorted array, remove the duplicates in place such that each element app ...
- 【LeetCode】80. Remove Duplicates from Sorted Array II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【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 ...
- 【LeetCode】026. Remove Duplicates from Sorted Array
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...
随机推荐
- Windows Server 2008 R2+SQL Server 2014 R2升级到Windows Server 2016+SQL Server 2016
环境: 操作系统:Windows Server 2008 R2 数据库:SQL Server 2014 因SQL Server 2016可以无域创建AlwaysOn集群,集群只剩下单节点也不会挂掉,故 ...
- 关于Python解释器
由于Python语言从规范到解释器都是开源的,所以理论上任何人都可以编写Python解释器来执行Python代码 目前存在以下几种主流的Python解释器 CPython CPython是官方版本的解 ...
- 4,list,list的列表嵌套,range
list 索引,切片+步长 # li = [, True, (, , , , , , '小明',], {'name':'alex'}] #索引,切片,步长 # print(li[]) # print( ...
- luogu1345 [USACO5.4]奶牛的电信Telecowmunication
对于每个点,把它拆成有权值为1的边相连的两个点,原边是inf. 边的起点统一加n,ss也加n 这就成了最小割 #include <iostream> #include <cstrin ...
- ORA-02437 违反主键
在给study用户下的semp表建立主键的时候,出现以下错误:SQL> alter table semp add constraint pk_emp primary key(empno);alt ...
- python linux安装anaconda
步骤: 1.在清华大学镜像站中下载anaconda版本:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ https://mirrors.t ...
- Axure:从简单搜索到联想搜索的部件制作
导读:最近一直都在整理原型部件,要说准备的最有感触的,当属搜索框无疑.搜索框的整理,前后加起来共耗时两天多.从最开始的按钮和文本框,到后来的图示,提示和联想查询.耗费了不少的心血,有必要总结一下,留个 ...
- POJ-1065 Wooden Sticks,排序+最长单减子序列!
Wooden Sticks 题意:有一台机器处理木材,最开始需要一分钟准备,如果后面处理的木材比前 ...
- The BLOB and TEXT Types
官网参考:https://dev.mysql.com/doc/refman/5.7/en/blob.html 字符串类型对应的存储需求 Data Type Storage Required CHAR( ...
- UITableView加载几种不同的cell
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...