import java.util.ArrayList; public class Main { public static void main(String[] args) { Integer[] nums = new Integer[]{3, 5, 2, 8, 4}; // 差异值 ---》异或运算 ^ // 相似值 ---》与运算 & ArrayList<Integer[]> pairs = new ArrayList<>(); for (int i = 0; i < nums.length; i++) { for (int j = i + 1; j < nums.length; j++) { pairs.add(new Integer[]{nums[i], nums[j]}); } } System.out.println(pairs.stream().filter(integers -> (integers[0] ^ integers[1]) > (integers[0] & integers[1])).count()); } }
标签:integers,pairs,nums,ArrayList,OD,new,华为,Integer,机试 From: https://www.cnblogs.com/kitor/p/17627242.html