标签:leetcode
https://oj.leetcode.com/problems/remove-element/
http://fisherlei.blogspot.com/2012/12/leetcode-remove-element.html
public class Solution { public int removeElement(int[] A, int elem) { // The order can be changed. // Use 2 pointers. // One to iterate the array, // One to copy the last elements back to array. if (A == null || A.length == 0) return 0; int start = 0; int end = A.length - 1; while (start <= end) { int v = A[start]; if (v == elem) { // Copy A[end] to A[start] A[start] = A[end]; end --; } else { start ++; } } return end + 1; } }
标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1598427