【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 ...
随机推荐
- Python全栈工程师之html学习笔记
https://www.bilibili.com/video/av15241731 笔记来源:黑马程序员 HTML(Hyper Text Markup Language):超文本标签语言 HTML标签 ...
- 牛客网暑期ACM多校训练营(第五场)F take(概率, 递推)
链接: https://www.nowcoder.com/discuss/84119 题意: 给定n个箱子, 每个箱子打开发现钻石的概率P(这里的P要除100), 每个钻石的重量, 有一个人只能持有一 ...
- CodeForces 699C - Vacations
题目链接:http://codeforces.com/problemset/problem/699/C C. Vacations time limit per test1 second memory ...
- mysqldump 常见报错及解决
mysqldump失败案例及解决: 1.mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when du ...
- PHP-redis命令之 字符串 (strings)
一.string (字符串) 1.set:设置键 $reids->set('mykey',111); 2.get:获取键 $redis->get('mykey'); 3.del:删除键 $ ...
- BZOJ 2176 Strange string ——最小表示法
本来想用来练习后缀自动机的,但是100w有点虚(事实证明确实T掉了). 只好上最小表示法. #include <cstdio> #include <cstring> #incl ...
- 刷题总结——火柴排队(NOIP2013)
题目: 题目背景 NOIP2013 提高组 Day1 试题 题目描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度.现在将每盒中的火柴各自排成一列,同一列火柴的高度互不相同,两列火柴之间 ...
- bzoj1734 [Usaco2005 feb]Aggressive cows 愤怒的牛 二分答案
[Usaco2005 feb]Aggressive cows 愤怒的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 407 Solved: 325[S ...
- Spoj-NPC2015A Eefun Guessing Words
Eefun Guessing Words Eefun is currently learning to read. His way of learning is unique, by trying ...
- java.util.ResourceBundle 用法小介
java中读取配置文件的信息可以采用properties这个类,但是当遇到国际化问题的时候还是不好解决,因而还是最好使用 ResourceBundle这个类,其实ResourceBundle本质上和P ...