[leetcode] 27. Remove Element 解题报告
2015-12-27 11:25
411 查看
题目链接:https://leetcode.com/problems/remove-element/
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.
思路:和move zero的题目差不多
代码如下:
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.
思路:和move zero的题目差不多
代码如下:
class Solution { public: int removeElement(vector<int>& nums, int val) { int k = 0; for(int i = 0; i < nums.size(); i++) if(nums[i] != val) swap(nums[i], nums[k++]); return k; } };
相关文章推荐
- ServerSAN解析(二):Nutanix实现存储与计算资源集成
- Spring MVC 集成 jackson-dataformat-xml 问题
- 用布局填充器填充ListView(继承BaseAdapter)
- Android 获取手机联系人实例代码详解
- VS使用Sublime Text 主题
- Win10系统下软件UI显示不完整解决方案
- ServerSAN解析(三):StoreVirtual存储软硬件完全解耦
- PremiumSoft Navicat for MySQL Enterprise Edition v8.0.27 注册码
- ServerSAN解析(三):StoreVirtual存储软硬件完全解耦
- MyEclipse激活步骤
- DHCP源码分析_子模块划分
- php学习日记第十一棒(计算器案例)
- php使用odbc执行复杂函数遇到的问题,sql语句直接在sqlserver数据库中运行有结果,使用php总是为空
- 【Java并发编程实战】----- AQS(三):阻塞、唤醒:LockSupport
- IntelliJ IDEA中怎样使用JUnit4
- 尼科彻斯定理
- NOI[2001] 炮兵阵地
- ServerSAN解析(四):FusionStorage存储与计算分合灵活部署
- ServerSAN解析(四):FusionStorage存储与计算分合灵活部署
- 总结报告