码迷,mamicode.com
首页 > 其他好文 > 详细

#27 Remove Element

时间:2017-05-01 14:19:22      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:leetcode   order   元素   mat   lin   family   ssi   can   ++   

题目链接:https://leetcode.com/problems/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.


//遍历元素,假设须要删除。用数组最后一个元素填充当前元素;下一个循环依旧考察当前元素
int removeElement(int* nums, int numsSize, int val) {
    for(int i = 0; i < numsSize; ++i)
        if(val == nums[i])
            nums[i--] = nums[--numsSize]; 
    return numsSize;
}


#27 Remove Element

标签:leetcode   order   元素   mat   lin   family   ssi   can   ++   

原文地址:http://www.cnblogs.com/cynchanpin/p/6791791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!