Remove Element_Leetcode_#27

来源:互联网 发布:防网络尖兵 编辑:程序博客网 时间:2024/06/07 03:21

题目:

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)代码如下:


1 0
原创粉丝点击