[Lintcode]Remove Element
来源:互联网 发布:mac怎么给手机换铃声 编辑:程序博客网 时间:2024/06/10 00:40
Given an array and a value, remove all occurrences of that value in place and return the new length.
The order of elements can be changed, and the elements after the new length don't matter.
Example
Given an array [0,4,4,0,0,2,4,4]
, value=4
return 4
and front four elements of the array is [0,0,0,2]
双指针.
public class Solution { /** *@param A: A list of integers *@param elem: An integer *@return: The new length after remove */ public int removeElement(int[] A, int elem) { int pos = 0; for(int i = 0; i < A.length; i++) { if(elem != A[i]) { A[pos++] = A[i]; } } return pos == 0 ? 0 : pos; }}
0 0
- [Lintcode]Remove Element
- [LintCode]Remove Element(Python)
- [lintcode]Remove Linked List 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
- HDU2001计算两点间的距离(C,Java用DecimalFormat格式控制)
- (转)Linux的chattr与lsattr命令详解
- arm平台函数传递参数,反汇编实例分析
- 地道的表达(二)
- R语言的饼图(pie)学习
- [Lintcode]Remove Element
- 【CSS3】设置动画的播放状态
- vector和list区别【转】
- java发送Email代码实现
- hive UDF 提取文本中的国家名
- 二分查找算法
- leetcode第20题——*Valid Parentheses
- 读算法导论日志:插入排序
- 利用BroadCastReceiver做网络判断