LeetCode Remove Duplicates from Sorted Array
来源:互联网 发布:武庆生c语言 编辑:程序博客网 时间:2024/05/16 05:59
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 =1; int len = nums.size(); if(nums.empty()) return 0; for(int i=0;i<len-1;i++) { if(nums[i] != nums[i+1]) { nums[count] = nums[i+1]; count++; } } return count; }};
0 0
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- leetcode 35: Remove Duplicates from Sorted Array
- [LeetCode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array
- Leetcode: Remove Duplicates from Sorted Array
- [leetcode] Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array
- [LeetCode]Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array
- [leetcode]Remove Duplicates from Sorted Array II
- ACD.Systems.ACDSee.Pro.v10.2.659.x64.Incl.Keymaker-CORE
- H5标签
- Java:如何把java文件打成Jar包/War包
- WPF中绘画和动画(三)
- shell java 执行
- LeetCode Remove Duplicates from Sorted Array
- cocos2dx增加front层并优先响应listener
- TCP 的那些事儿(上)
- 编程修养(四)
- Spring IOC--Bean的装配(使用注解定义Bean)
- JSSIP源码简介-关于SIP协议使用的一个JavaScript库/JS在通讯中的应用
- 【Java】游戏小程序-超级玛丽(代码渗入)
- SM58 信息 IDoc 5 : 发送, 未到达 ; 成功将数据传送到端口
- C# sha1加密