码迷,mamicode.com
首页 > 编程语言 > 详细

leetcode第27题:删除vector数组的元素(array)

时间:2015-06-17 23:23:07      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

题目:

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.

这个比较简单,掌握vector的用法即可。

 1 int removeElement(vector<int>& nums, int val) {
 2         vector<int>::iterator it;
 3         for(it=nums.begin();it!=nums.end();)
 4         {
 5             if(val==*it)
 6               it = nums.erase(it);
 7             else
 8               it++;
 9         }
10         return nums.size();
11  }

 

leetcode第27题:删除vector数组的元素(array)

标签:

原文地址:http://www.cnblogs.com/WonderHow/p/4584489.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!