leetcode — remove-element

/**
* Source : https://oj.leetcode.com/problems/remove-element/
*
* Created by lverpeng on 2017/7/12.
*
* 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.
*/
public class RemoveElement { /**
* 判断不等于value的值个数
* @param num
* @param value
* @return
*/
public int remove (int[] num, int value) {
int pos = 0;
for (int i = 0; i < num.length; i++) {
if (num[i] != value) {
pos ++;
}
}
return pos;
} public static void main(String[] args) {
RemoveElement removeElement = new RemoveElement();
int[] num = new int[]{1,2,3,4,5,5,6};
System.out.println(removeElement.remove(num, 5));
}
}
上一篇:【干货】Chrome插件(扩展)开发全攻略(转)


下一篇:[BZOJ]4405: [wc2016]挑战NPC(带花树)