Remove Element leetcode
2016-01-04 20:07
246 查看
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.
Subscribe to see which companies asked this question
利用双指针思想
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Subscribe to see which companies asked this question
利用双指针思想
int removeElement(vector<int>& nums, int val) { int slow = 0, fast = 0; while (fast < nums.size()) { if (nums[fast] != val) nums[slow++] = nums[fast]; fast++; } return slow; }
相关文章推荐
- OpenJudge_P3532 最大上升子序列和(DP)
- log4net配置文件基本配置
- 生产者消费者-线程-链表-队列实现
- Summary for my 4 months
- [LeetCode] Bulb Switcher 灯泡开关
- handlebars 比较
- SVM(support victor machine)
- asiainfo亚信——实习日记
- 下载电影的网站
- 使用spritekit开发iOS游戏 【第一章 入门】
- 伪异步IO理解
- MySQL的分页优化
- Android布局控件之LinearLayout详解
- js html时间控件2
- 2015年读书总结
- Http请求中的Content-Type
- Eclipse中出现莫名其妙的ClassNotFound的情况
- 关于nodejs模块安装后找不到包解决办法
- Gatling实战(一)
- 解决Eclipse构建Maven项目时web.xml is missing错误