博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
27. Remove Element
阅读量:4663 次
发布时间:2019-06-09

本文共 816 字,大约阅读时间需要 2 分钟。

Given an array and a value, remove all instances of that value in place and return the new length.

Do not allocate extra space for another array, you must do this in place with constant memory.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

Example:

Given input array nums = [3,2,2,3]val = 3

Your function should return length = 2, with the first two elements of nums being 2.

1 int removeElement(int* nums, int numsSize, int val) { 2     int i; 3     int k = 0; 4     int j = 0; 5     for(i = 0; i < numsSize; i++) 6     { 7         if(val == nums[i]) 8             k++; 9     }10     for(i = 0; i < numsSize; i++)11     {12         if(val != nums[i])13             nums[j++] = nums[i];14     }15     return j;16 }

 

转载于:https://www.cnblogs.com/boluo007/p/5528444.html

你可能感兴趣的文章
tensorflow安装
查看>>
AGC001 E BBQ Hard
查看>>
js写的ajax
查看>>
解析器组合子
查看>>
AtCoder Regular Contest 097
查看>>
openssl 生成证书
查看>>
aspx页面生成xml数据
查看>>
转:do{...}while(0)的意义和用法
查看>>
nginx反向代理(动静分离)
查看>>
一些加快 程序运行速度的方法
查看>>
Go语言管道
查看>>
查看当前使用的shell
查看>>
基于 muse-ui 封装一个微信公众号上传插件 实现多图上传
查看>>
vue面试题!!!
查看>>
hdu 3007【最小圆覆盖-随机增量法模板】
查看>>
10.15作业
查看>>
angularJs实现修改功能
查看>>
网络流二十四题之假期的宿舍
查看>>
ASP.NET MVC5(二):控制器、视图与模型
查看>>
眼高手低,你有这个毛病吗?
查看>>