[LeetCode]80. Remove Duplicates from Sorted Array II
2016-04-17 17:36
393 查看
80. Remove Duplicates from Sorted Array II
Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given sorted array nums = [1,1,1,2,2,3], Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3. It doesn't matter what you leave beyond the new length.
分析
这个题目和这个题目类似。源码
class Solution { public: int removeDuplicates(vector<int>& nums) { if (nums.size() <= 2) return nums.size(); int index = 2; for (int i = 2; i < nums.size(); i++){ if (nums[i] != nums[index - 2]) nums[index++] = nums[i]; } return index; } };
相关文章推荐
- 遭遇Reply from : TTL expired in transit.
- sql server的 update from 语句的深究
- 数据库插入数据之select into from与insert into select区别详解
- javascript add event remove event
- 详解jQuery中的empty、remove和detach
- Select data from an Excel sheet in MSSQL
- IE不支持option的display样式,只能使用remove和add
- jquery使用remove()方法删除指定class子元素
- FROM_UNIXTIME 格式化MYSQL时间戳函数
- Oracle中实现MySQL show index from table命令SQL脚本分享
- Lua的table库函数insert、remove、concat、sort详细介绍
- MongoDB Remove函数的3个常见用法
- jquery之empty()与remove()区别说明
- ASP.NET之Response.Cookies.Remove 无法删除COOKIE的原因
- Datatable删除行的Delete和Remove方法的区别介绍
- jQuery中remove()方法用法实例
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- python sort、sorted高级排序技巧
- Python 列表排序方法reverse、sort、sorted详解
- python中List的sort方法指南