去除数组中绝对值相同元素

两种方法:

 

 方法1

public void method1() { 
	int [] a={55,6,4,4,8,-8,8,8}; 
	Map map=new HashMap(); 
	for(int i=0;i 

 

 

方法2

public void method2(){ 
	int [] arr={55,6,4,4,8,-8,8,8}; 
	Set ts = new TreeSet();
	for (int n : arr) {
		ts.add(Math.abs(n));
	}
	System.out.println(ts.size());
}

 

你可能感兴趣的:(算法)