26. Remove Duplicates from Sorted Array
2016-03-14 13:05
302 查看
//64ms class Solution { public: int removeDuplicates(vector<int>& nums) { if(!nums.size()) return 0; for(auto a=nums.begin()+1;a!=nums.end();a++) { if(*a==*(a-1)) { nums.erase(a); a--; } } return nums.size(); } }; //32ms class Solution { public: int removeDuplicates(vector<int>& nums) { if(!nums.size()) return 0; int cur=0; for(auto a=nums.begin();a!=nums.end();a++) { if(*a>nums[cur]) { nums[++cur]=*a; } } return cur+1; } };
相关文章推荐
- Linux下简单线程池的实现
- Web系统大规模并发:电商秒杀与抢购
- ModelMap和ModelAndView
- Dom4j工具类
- 《我是一只IT小小鸟》读后感
- 21. Merge Two Sorted Lists
- 19. Remove Nth Node From End of List
- Leetcode 13. Roman to Integer
- java jps命令
- json 筛选数据 $.grep过滤数据
- UITableView——点击某一行移动到指定位置
- 解决sublime3,python3不能输出中文问题
- 通讯录联系人,带右边索引案例
- Leetcode 9. Palindrome Number
- Leetcode 7. Reverse Integer
- 操作系统: 最佳适配算法和邻近适配算法的模拟实现(内存分配算法)
- Keysight34401数字多用表远程遥控读取数据
- 在网页中插入百度地图
- Leetcode 6. ZigZag Conversion
- Leetcode 2. Add Two Numbers