【LeetCode从零单排】No27.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.


代码

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;
    }
}


代码下载:https://github.com/jimenbian/GarvinLeetCode


/********************************

* 本文来自博客  “李博Garvin“

* 转载请标明出处:http://blog.csdn.net/buptgshengod

******************************************/




你可能感兴趣的:(java,LeetCode)