leetcode--26. Remove Duplicates from Sorted Array
来源:互联网 发布:信捷plc步进指令编程 编辑:程序博客网 时间:2024/06/10 07: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) { if(nums.empty()) return 0; int pos = 1; for(int i = 1; i < nums.size(); ++i){ if(nums[i] != nums[i - 1]) nums[pos++] = nums[i]; } return pos; }};
0 0
- [LeetCode]26.Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode --- 26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- [Leetcode] 26. Remove Duplicates from Sorted Array
- 【leetcode】26. Remove Duplicates from Sorted Array
- 【leetcode】 26. Remove Duplicates from Sorted Array
- [leetCode]26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array LeetCode
- 【LeetCode】26. Remove Duplicates from Sorted Array
- [LeetCode]26. Remove Duplicates from Sorted Array
- leetcode 26. Remove Duplicates from Sorted Array
- LeetCode *** 26. Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode - 26. Remove Duplicates from Sorted Array
- leetcode-26. Remove Duplicates from Sorted Array
- 26.[Leetcode]Remove Duplicates from Sorted Array
- 两台笔记本电脑之间实现屏幕扩展
- HTML5 浏览器支持
- 2017.1.15【初中部 NOIP提高组】模拟赛B组 七天使的通讯(angelus) 题解
- 生物信息学(BioInfo) - Linux 常用操作
- Activity学习
- leetcode--26. Remove Duplicates from Sorted Array
- PPP协议(TCPIP协议第二版)
- ArcGIS Engine 开发入门(一)
- c语言中的字符数组与字符串(转载)
- .h分离类
- zoj2022
- Redis教程之基础-五种数据基本操作
- 利用正则表达式从文件路径中匹配文件名
- 453. Minimum Moves to Equal Array Elements*