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 next = 0; for(int i = 0; i < A.length; i++) { if(A[i] != elem) { A[next++] = A[i]; } } return next; } }
/********************************
* 本文来自博客 “李博Garvin“
* 转载请标明出处:http://blog.csdn.net/buptgshengod
******************************************/
【LeetCode从零单排】No27.Remove Element
原文地址:http://blog.csdn.net/buptgshengod/article/details/43764195