You are viewing a single comment's thread. Return to all comments →
Java with single loop
public static int hackerlandRadioTransmitters(List<Integer> x, int k) { int counter = 0; int trans = 0; int minInRange = 0; x = x.stream().distinct().sorted().collect(toList()); for(int n:x){ if(trans == 0){ trans = n; counter++; } else if(inRange(trans, n, k)){ if (minInRange == 0){ minInRange = trans; trans = n; } else if (inRange(minInRange, n, k)){ trans = n; } } else { trans = n; minInRange = 0; counter++; } } return counter; }
Seems like cookies are disabled on this browser, please enable them to open this website
Hackerland Radio Transmitters
You are viewing a single comment's thread. Return to all comments →
Java with single loop