26. Remove Duplicates from Sorted Array(easy)
来源:互联网 发布:珍珠颜色优化 编辑:程序博客网 时间:2024/05/09 06:15
题目
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array nums = [1,1,2]
,
Your function should return length = 2
, with the first two elements of nums being 1
and 2
respectively. It doesn't matter what you leave beyond the new length.
题目有说不允许额外的空间代表着直接修改原数组,重复多少次则后面的元素往前移多少单位
class Solution {public: int removeDuplicates(vector<int>& nums) { int count = 0; int n=nums.size(); for(int i=1;i<n;i++){ if(nums[i]==nums[i-1]) count++; nums[i-count]=nums[i]; } return n-count; }};
0 0
- 26. Remove Duplicates from Sorted Array [easy]
- 【Easy】26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array(easy)
- leetcode26[easy]--- Remove Duplicates from Sorted Array
- 【Leet Code】26. Remove Duplicates from Sorted Array---Easy
- Easy-题目29:26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array [easy] (Python)
- Leetcode 26. Remove Duplicates from Sorted Array (Easy) (cpp)
- Leetcode 26. Remove Duplicates from Sorted Array (Easy) (java)
- Easy 7 Remove Duplicates from Sorted Array(26)
- Easy 26题 Remove Duplicates from Sorted Array(BUT NOT EASY)
- [LeetCode] 026. Remove Duplicates from Sorted Array (Easy) (C++/Java)
- [Leetcode 26, easy] Remove Duplicates from Sorted Array
- (算法分析Week9)Remove Duplicates from Sorted Array[Easy]
- LeetCode-Easy刷题(7) Remove Duplicates from Sorted Array
- [LeetCode]26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- 搭建本地maven仓库实战
- requestmethod.get和post的区别
- 强大的武器
- 卫星地图在农业土地种植管理的应用
- 项目成本管理·九
- 26. Remove Duplicates from Sorted Array(easy)
- Linux命令大全
- String,StringBuffer与StringBuilder的区别??
- 基本数据结构和算法的前端实现
- Windows Server2012 R2安装IIS时提示找不到源文件
- python基础-dir()和__dict__
- <Android 开源库> Matisse,来自知乎的PhotoPicker
- USB的枚举过程与描述符(字)
- jquery实现导航栏吸顶效果(简洁版)