Remove Element
2015-07-20 21:44
239 查看
Problem: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.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
public static int removeElement(int[] nums, int val) { int i=0,j=0; while(j<nums.length){ if(nums[j]!=val) nums[i++]=nums[j]; j++; } return i; }
相关文章推荐
- K-means聚类算法
- sun.jnu.encoding
- hibernate学习之路——hello word
- Oracle的触发器
- hdoj1090A+B for Input-Output Practice (II)
- 随笔 2015 7 20
- JSP/SERVLET入门教程--Servlet 使用入门
- JS检查浏览器类型和版本
- JS检查浏览器类型和版本
- JS检查浏览器类型和版本
- 2、实现不同子网之间的信息交流(互相可以PING通)
- 3D打印
- wyh2000 and pupil
- 【JAVA基础】父类类型做形参
- JAVA基础之继承
- Java多线程使用Synchronized需注意锁的永远是对象
- 根据切割下来的字符串断裂成不同的部分
- Sql省市三级联动一张表
- 理解HTTP幂等性(转)
- [数学] AOJ 0009 素数筛选 Prime Number