爪哇(计数不同的整数) [英] Java ( Counting Distinct Integers )
本文介绍了爪哇(计数不同的整数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你如何在一个数组返回不同的/唯一值的数量例如:
INT [] A = {1,2,2,4,5,5};
解决方案
设置<整数GT; S =新的HashSet<整数GT;();
对(INT I:一)s.add(ⅰ);
INT distinctCount = s.size();
how do you return number of distinct/unique values in an array for example
int[] a = {1,2,2,4,5,5};
解决方案
Set<Integer> s = new HashSet<Integer>();
for (int i : a) s.add(i);
int distinctCount = s.size();
这篇关于爪哇(计数不同的整数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文