zoukankan      html  css  js  c++  java
  • 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.

    #include<iostream>
    #include<vector>
    using namespace std;
    
    int removeElement(int A[], int n, int elem) {
    	int newlength = 0;
    	for (int i = 0; i < n;++i)
    	{
    		if (A[i] != elem)
    		{
    			A[newlength] = A[i];
    			newlength++;
    		}
    	}
    	return newlength;
    }

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    UVA10361
    △UVA10494
    △UVA465
    △UVA10106
    △UVA424
    阶乘的精确值
    小学生算术
    UVA156
    △UVA120
    linux应用之ntpdate命令联网同步时间
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4750688.html
Copyright © 2011-2022 走看看