java comparator hackerrank solution - java
For Explanation Watch Video :
Code::
import java.util.*;
// Write your Checker class here
class Checker implements Comparator<Player>{
@Override
public int compare(Player p1,Player p2){
String name1 = p1.name;
String name2 = p2.name;
int score1 = p1.score;
int score2 = p2.score;
if(score1<score2){
return 1;
}else if(score1>score2){
return -1;
}else {
return name1.compareTo(name2);
}
}
}
class Player{
Comments
Post a Comment