首页 > 编程语言 > 详细

删除数组中的重复元素

时间:2017-08-20 10:58:19      阅读:281      评论:0      收藏:0      [点我收藏+]
public static int[] getNewArray(int[] array) {
		int[] temp = new int[array.length];
		int t = 0;
		for(int i=0;i<array.length;i++) {
			boolean flag = true;
			for(int j=0;j<i;j++) {
				if(i==0) {
					continue;
				}else if(array[i]==temp[j]) {
					flag = false;
					break;
				}
			}
			if(flag) {
				temp[t++] = array[i];
			}
		}
		int[] newArray = new int[t];
		System.arraycopy(temp, 0, newArray, 0, t);
		return newArray;
	}
	
技术分享

运行结果:

技术分享

 


  

删除数组中的重复元素

原文:http://www.cnblogs.com/houxudong/p/7399067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!