leetcode_27_ Remove Element (easy)
2015-11-02 11:15
387 查看
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.
Subscribe to see which companies asked this question
解题:
简单
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int now = -1;
for(int i = 0; i<nums.size();i++){
if(nums[i]!=val){
nums[++now] = nums[i];
}
}
return now+1;
}
};
相关文章推荐
- 初识UML
- css3动画模块transform transition animation属性解释
- xcode 弹出的错误 1 <Xcode cannot launch apps on the simulated device “iPhone 5s”, as it is cur>
- JSP中application session request cookie 生命周期的问题
- WebService到底是什么? .
- ActionResult 的返回类型
- 华为S5700S配置总结
- httpclient
- C++11 多线程下生产者消费者模型详解
- Android项目使用support v7时遇到的各种问题
- 在Xcode中使用Git进行源码版本控制
- 1的个数
- 浅谈Java源码
- 【转】android如何查看cpu的占用率和内存泄漏
- 周末龙泉寺行记
- java多线程问题,线程交替执行
- IOS MPMoviePlayerViewController视频播放(MediaPlayer)
- Deep Learning 备忘与总结
- 数据解析
- Same Tree