[LeetCode-27] Remove Element(从数组删除指定的元素)

来源:互联网 发布:bruno mars唱功知乎 编辑:程序博客网 时间:2024/05/05 23:15

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.
【分析】该题目和http://blog.csdn.net/xy010902100449/article/details/48790661
性质是一样的。


代码如下:

int removeElement(int* nums, int numsSize, int val)  {    if(numsSize <= 0)        return 0;    int i = 0;    int count = 0;    for(i = 0;i < numsSize;i++) {        if(nums[i] == val) {            nums[count++]  = nums[i];        }    }    return count;}
0 0
原创粉丝点击