码迷,mamicode.com
首页 > 其他好文 > 详细

Remove Element

时间:2015-01-29 17:40:24      阅读:126      评论: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.

我的解法:

(1)算法思想:

记j=0,len=n,遍历一次数组,遇到与elem相等的元素,len--;否则,将A[i]赋值给A[j++]。

(2)代码如下:


Remove Element

标签:

原文地址:http://blog.csdn.net/littlebob180/article/details/43273389

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