网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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数组元素删除
URL网址:http://bjjierui.cn/article/gogceg.html

其他资讯