26. Remove Duplicates from Sorted Array
来源:互联网 发布:积分兑换系统源码 编辑:程序博客网 时间:2024/05/14 10:36
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]
,
solution:
class Solution {public: int removeDuplicates(vector<int>& nums) { int sz = nums.size(); if(sz<=1) return sz; auto p = nums.begin(); auto c = p+1; while(c<nums.end()){ if(*p==*c){ c = nums.erase(c); } else{ p++; c++; } } return nums.size(); }};
心得:思路简单,运行速度慢 每次erase 后 nums.end()发生改变
运行速度:慢
0 0
- [LeetCode]26.Remove Duplicates from Sorted Array
- 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
- 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]26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array LeetCode
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- Mouse Events
- ZOJ 3202Second-price Auction(排序)
- 酒店管理系统
- android Viewpage 无限循环播放
- java(16)--servlet+jsp+四大域+javabean+开发模式
- 26. Remove Duplicates from Sorted Array
- Java笔记19:Java匿名内部类
- Android 启动时间优化 <22>
- 打包时的配置
- ZOJ 3203Light Bulb(数学)
- wamp开启rewrite_module重写功能启用.htaccess文件
- 华为机试题:将十六进制字符串形式内容转为内存值形式(java)
- 例题 6-15 UVA 10305 Ordering Tasks 给任务排序
- Dom4j的使用(全而好的文章)