LeetCode题解——Remove Element
2015-07-29 10:42
351 查看
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.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
class Solution { public: int removeElement(vector<int>& nums, int val) { int k = 0; int i = 0, N = nums.size(); while(i<N){ if(nums[i]!=val) nums[k++] = nums[i]; i++; } return k; } };
相关文章推荐
- jenkins原有邮箱的设置测试通过
- 一个最简单的java web项目的部署
- 使用Objective-C的文档生成工具:appledoc
- WPF 实现按钮的任意拖拽
- 终端趣味sl 编译出错(curses.h:没有那个文件或目录)解决
- Qt 5.3 下OpenCV 2.4.11 开发(2)摄像头采集
- 在开发过程中调试报表插件详细教程
- mysql实战之 批量update
- IOS XMPP引入时产生错误信息 “libxml/tree.h no such file or directory”
- FCC 新规可能禁止在 WiFi 路由器安装 OpenWRT
- SiteMesh在JSP中的页面装饰
- Rational Team Concert 的使用
- POJ 1276 Cash Machine 最多机器
- hdu 1010 Tempter of the Bone
- 开发服务器端时的框架选择
- PostgreSQL Concurrency with MVCC
- Foundation Framework 基本数据封装 NSNumber、NSValue、NSData
- 多线程、多任务管理 简单demo
- Create pdf
- CentOS 6.5_x64安装Oracle 11g R2 亲测