leetcode刷题,总结,记录,备忘 80
来源:互联网 发布:网络打印共享器怎么用 编辑:程序博客网 时间:2024/04/25 06:02
leetcode80 Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
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.
Subscribe to see which companies asked this question
class Solution {public: int removeDuplicates(vector<int>& nums) { set<int> s1; set<int> s2; for (int i = 0; i < nums.size(); ++i) { pair<set<int>::iterator, bool> p; if (i % 2 == 0) { p = s1.insert(nums[i]); if (p.second == false) { nums.erase(nums.begin() + i); i--; } } else { p = s2.insert(nums[i]); if (p.second == false) { nums.erase(nums.begin() + i); i--; } } } return s1.size() + s2.size(); }};
0 0
- leetcode刷题,总结,记录,备忘 80
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode刷题,总结,记录,备忘 108
- 点赞时代,你为什么被人绝交?
- 关于自定义Dialog的那些事
- Staring at a blank desktop, due to event 4006
- Windows Server 2012: Deactivating UAC
- 百度地图实现最简单的定位功能(无地图界面)
- leetcode刷题,总结,记录,备忘 80
- PostgreSQL新手入门
- Linux常用命令(自我总结)
- 图片的内存优化
- struts2总结
- cakephp中使用ajax获得数据,动态折线显示
- 在vs2010下编译OpenSSL
- ORA-06553:PLS-306:wrong number or types of arguments in call to ''
- 设置不自动弹出软键盘的最简洁解决方案