You are viewing a single comment's thread. Return to all comments →
// Java public static int getTotalX(List<Integer> a, List<Integer> b) { int result = 0; int minOfB = Collections.min(b); int maxOfA = Collections.max(a); Set<Integer> factors = new HashSet<Integer>(); for(int i= maxOfA; i<= minOfB; i++){ int count = 0; for(int item : a){ if(i%item ==0) count ++; } if(count==a.size()) factors.add(i); } for(int f: factors){ int count = 0; for(int item : b){ if(item%f ==0) count++; } if(count == b.size()) result++; } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →