Remove Element
来源:互联网 发布:文网文增加域名 编辑:程序博客网 时间:2024/06/05 23:09
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.
解题思路:
题目大意,删除数组中的指定元素。实现方法比较简单,通过指针,可以在O(n)时间复杂度内解决。
Code:
int removeElement(int A[], int n, int elem) { int pElem=0; for(int i=0;i<n;i++) if(elem!=A[i]) { A[pElem++]=A[i]; } return pElem; }
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
- .net笔记一
- HDOJ 题目Largest prime factor(水题)
- linux常用命令大全(转)
- 文本颜色和效果——text-decoration
- struts2乱码问题
- Remove Element
- POJ 1459 Power Network (多源点/汇点最大流问题)
- JS(JQEERY) 获取JSON对象中的KEY VALUE
- contiki系统分析:时钟
- Linux软连接和硬链接
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in)) ; 语句解析
- The Android ION memory allocator
- Executor框架
- Sql语句-case when then else end