
##题目
####Remove Element
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.
##解题思路
该题是移除数组中给定的元素。这里可以设定两个指针i和j,如果A[j]不是要删除的元素,则A[i]=A[j],否则j往前移动。这样j指针相当于遍历整个数组,而i指针则负责保存剩余的元素。这样只需要遍历一遍数组即可。
##算法代码
代码采用JAVA实现:
1 |
public class { |




近期评论