Remove Element
来源:互联网 发布:javascript与jsp 编辑:程序博客网 时间:2024/05/01 15: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.
刚看到题目,觉得挺简单,但因为没有好好在脑子里面执行一遍,所以逻辑上有个小错误,把两个if顺序弄反了
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
刚看到题目,觉得挺简单,但因为没有好好在脑子里面执行一遍,所以逻辑上有个小错误,把两个if顺序弄反了
int removeElement(int A[], int n, int elem) {int offset = 0;for (int i = 0; i < n; i++){if ( i-offset >= 0)//刚开始两个if搞错顺序了A[i-offset] = A[i];if (A[i] == elem)offset++;}return n - offset;}
0 0
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- 1324:算法2-2:有序线性表的有序合并
- Windows 7安装CentOS6.5 双系统
- Grinder
- WPF: 把引用的dll移动到自定义路径
- Linux下找不到Android设备的解决方法
- Remove Element
- 【时光网评出的得分最高的100部电影】一定要抽时间去看看!
- ONVIF的抓图
- 第一次编程作业-求两个整数的最大公约数
- 基因这东西真的很神奇:有其父必有其子! [哈哈][哈哈][哈哈]
- 【转】山寨一个 Boost.Bind
- PHP名师们变身企业HR,来传智播客“招聘”PHP 程序员
- 用java socket实现了一个简单的http服务器
- 爱Fashion爱新奇的不要喜错过FashionEmpress哦,这里都是无水印美图哦!!