Given a string input of a company id and rating, sort them by rating in descending order.

  • 0

    input ="1005 2\n1001 5\n1002 5\n1004 1"

    var companyRating = function(input) {


  • 0
    This post is deleted!

  • 0
            String input = "1005 2\n1001 5\n1002 5\n1004 1";
            String[] arr = input.split("\n");
            Arrays.sort(arr,new Comparator<String>(){
                public int compare(String s1, String s2){
                    String[] s1Arr = s1.split(" ");
                    String[] s2Arr = s2.split(" ");
                    return Integer.valueOf(s1Arr[1]) - Integer.valueOf(s2Arr[1]);
            for (String s : arr)

  • 0

    @hikkiii_p It should be displaying in descending order, thus the compare function should be fixed a little bit.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.