标签:style blog color io ar for div sp log
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.
思路:
1 class Solution { 2 public: 3 int removeElement( int A[], int n, int elem ) { 4 int idx = 0; 5 for( int i = 0; i < n; ++i ) { 6 if( A[i] != elem ) { 7 A[idx++] = A[i]; 8 } 9 } 10 return idx; 11 } 12 };
标签:style blog color io ar for div sp log
原文地址:http://www.cnblogs.com/moderate-fish/p/3959203.html