LeetCode27.RemoveElement数组元素删除
27. Remove Element

成都创新互联基于分布式IDC数据中心构建的平台为众多户提供成都移动机房 四川大带宽租用 成都机柜租用 成都服务器租用。
Given an array and a value, remove all instances of that value in place and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
Example:
Given input array nums = [3,2,2,3], val = 3
Your function should return length = 2, with the first two elements of nums being 2.
题目大意:删除容器中指定的重复元素,然后返回容器的长度。要求不能申请数组来处理。
class Solution {
public:
int removeElement(vector& nums, int val) {
for(int i = 0; i < nums.size(); i++)
{
if(nums[i] == val )
{
nums.erase (nums.begin() + i );
i--;
}
}
return nums.size();
}
}; 2016-08-05 20:42:00
文章名称:LeetCode27.RemoveElement数组元素删除
标题链接:http://scpengxi.com/article/gogceg.html
其他资讯
- mongodb存储时间格式是什么-创新互联
- 微信公众号url如何获取,怎样获取微信公众号url
- win7怎么通过设备管理器禁用指定设备
- jquery时间显示时间,jquery 日期时间控件
- wr880n无线路由器设置 wr886n路由器设置
- 在linux中cd命令 linux使用cd命令
- windows系统安装的安装程序在c盘哪里?(原版windows怎么安装程序)
- 玩游戏盒的游戏在Win10不能下载吗?(windows10的游戏下载地址)
- ArcGIS文件转换为地理数据库的必要性及步骤(arcgis文件地理数据库)
- 新加坡ovh服务器(MegalayerVPS和HostUSVPS新加坡机房评测对比)
