Remove Element
2015-09-02 00:32
169 查看
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.
Analyse: You have to delete all elements equal to the value and return the new length.
Runtime: 4ms.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Analyse: You have to delete all elements equal to the value and return the new length.
Runtime: 4ms.
class Solution { public: int removeElement(vector<int>& nums, int val) { int index = 0; for(int i = 0; i < nums.size(); i++){ if(nums[i] != val) nums[index++] = nums[i]; } return index; } };
相关文章推荐
- Linux程序包编译安装
- UIView,UIButton,UIImageView等视图设置圆角,设置阴影,设置边框的方法
- ldd入门之学习环境的配置
- 最近读的书
- HDOJ 题目3397 Sequence operation(线段树区间覆盖异或合并)
- OpenCV 对图像进行掩码操作
- 基于spring框架的BS构架web应用程序的一些学习心得
- 8-Advice for Applying Machine Learing
- C#的装箱拆箱
- C++成员函数的 重载、隐藏、覆盖分析
- js的局部变量和全局变量的定义形式举例
- Android开发中颜色的自定义方法
- ios开发之UI基础--应用管理xib-九宫格布局
- Xhprof----facebook开源的,轻量级的PHP性能分析工具
- Android 几种发送短信的方法
- 欧姆龙PLC以太网FINSTCP通信例程与操作步骤
- 数据结构之---C语言实现平衡二叉树(AVL树)
- zoj 2676 Network Wars 【0-1分数规划 + 最小割】 【吃一堑长一智】
- C#StringBuilder的使用
- CCFontAtlasCache,CCFontCharMap,CCFontFNT,CCFontFreeType解析