27.Remove Element(Array)
2015-09-15 10:31
302 查看
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 ret = 0; int newI = 0; for(int i = 0; i < nums.size(); i++){ if(val!=nums[i]){ ret++; nums[newI++] = nums[i]; } } return ret; } };
相关文章推荐
- 阿里服务器配置swap
- o怎么样racle输入dmp数据库文件
- 稻盛和夫:人该如何合理地与欲望共度一生
- JS实现仿FLASH效果的竖排导航代码
- iOS 禁止横屏
- WinIO3.0在win7 64位系统下的使用
- word转pdf还有什么好的方法
- c#正则替换之Regex.Escape
- webservice
- 51nod 1429:巧克力
- 二十岁出头的时候上,你一无所有,你拥有一切。
- MFC中listbox控件中各种属性的详解
- 51nod 1429:巧克力
- GTM同步测试日志
- sql server 中将由逗号“,”分割的一个字符串,转换为一个表,并应用与 in 条件...
- sql server 中将由逗号“,”分割的一个字符串,转换为一个表,并应用与 in 条件
- STL容器stack栈
- html iframe高度自适应
- 基础篇——队列,栈
- PHP---ajax传递POST值(包含html标记)到提交页面数据丢失或乱码