Remove Element
2015-08-03 21:11
204 查看
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Solution:
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Solution:
class Solution { public: int removeElement(vector<int>& nums, int val) { for(auto iter = nums.begin(); iter != nums.end();) { if(*iter == val) { iter = nums.erase(iter); } else iter++; } return nums.size(); } };
相关文章推荐
- hdu1241详解 Java广搜搞定
- 黑马程序员——while语句+for语句+for嵌套练习-第3天
- Android项目导入出错
- 大学里
- PreparedStatement是如何防止SQL注入的
- 基本组件之RadioGroup与CheckBox
- 如何给网页加上标题和logo?
- 最短路径—Dijkstra算法和Floyd算法
- VMware vSphere 创建虚拟机时SCSI适配器的选择
- HDOJ 1087 Super Jumping! Jumping! Jumping!(LIS变形)
- Search in Rotated Sorted Array
- poj-Dividing问题
- hdoj 1005 Number Sequence
- 九度oj 二叉树遍历 题目1184
- arm ubuntu 按键关机的实现
- hdu5336&15年多校集训(4)j题(bfs+模拟)
- 用两个栈实现一个队列
- 第七章 子查询
- 37.创业团队不是天堂
- Hdu 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)