标签:style class blog code java color
题目:
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.
解答:注意,在原数组上修改,覆盖原数组即可
public class Solution { public int removeElement(int[] A, int elem) { int num=0; int len=A.length; for(int i=0;i<len;i++){ if(A[i]!=elem) A[num++]=A[i]; } return num; } }
---EOF---
【LeetCode】Remove Element,布布扣,bubuko.com
标签:style class blog code java color
原文地址:http://blog.csdn.net/navyifanr/article/details/24867137