hacker rank 36th problem solution(JAVA COMPARATOR)
36.JAVA COMPARATOR
class Checker implements Comparator<Player>{
public int compare(Player a, Player b){
if (a.score == b.score){
return a.name.compareTo(b.name);//alphabetically
} else {
return b.score - a.score;//decreasing
}
}
}
Comments