80. Remove Duplicates from Sorted Array II LeetCode
来源:互联网 发布:淘宝店铺风格定位 编辑:程序博客网 时间:2024/05/23 10:45
题意:给出一个排好序的数组,让你使得数组每个元素最多出现2次,把多余的去掉。
题解:直接模拟。
class Solution {public: int removeDuplicates(vector<int>& nums) { int ans = 0,count = 1; int n = nums.size(); if(n == 0) return 0; int num = nums[0]; for(int i = 1; i < n; i++) { if(nums[i] == num) { count++; if(count <= 2) nums[++ans] = nums[i]; } else { ans++; nums[ans] = nums[i]; num = nums[i]; count = 1; } } return ans + 1; }};
0 0
- leetcode——26. Remove Duplicates from Sorted Array && 80. Remove Duplicates from Sorted Array II
- LeetCode 26. Remove Duplicates from Sorted Array && 80. Remove Duplicates from Sorted Array II
- leetcode.array--80. Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array II
- [leetcode] Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array II
- LeetCode-Remove Duplicates from Sorted Array II
- [leetcode] Remove Duplicates from Sorted Array II
- LeetCode - Remove Duplicates from Sorted Array II
- LeetCode:Remove Duplicates from Sorted Array II
- LeetCode | Remove Duplicates from Sorted Array II
- Leetcode: Remove Duplicates from Sorted Array II
- 【leetcode】Remove Duplicates from Sorted Array II
- 千万级规模高性能、高并发的网络架构经验分享
- 网络开发注意事项
- linux下把eth1改为eth0
- iOS 设置头像圆角效果
- UTF-8编码规则(转)
- 80. Remove Duplicates from Sorted Array II LeetCode
- div水平居中与垂直居中
- Android学习-Layout布局
- <Torch>~解惑篇-1.深度学习平台的选择(溪欲焰)
- jsoup 解析HTML信息
- Windbg调试命令详解
- zlib的交叉编译 for海思
- 前端猿的成长历程
- hrbust 哈理工oj 2011 一等队形【dp】