Created
April 21, 2021 03:56
-
-
Save rohanjai777/c874e5bf5f729eb9b316b9cb33da69d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String largestNumber(final int[] arr) { | |
int n = arr.length; | |
String sa[] = new String[n]; | |
for(int i=0;i<n;i++){ | |
sa[i] = Integer.toString(arr[i]); | |
} | |
Arrays.sort(sa, new Comparator<String>(){ | |
public int compare(String a, String b){ | |
String s1 = a+b; | |
String s2 = b+a; | |
return s1.compareTo(s2); | |
} | |
}); | |
String s = ""; | |
for(int i=0;i<n;i++){ | |
s=sa[i]+s; | |
} | |
if(s.charAt(0) == '0'){ | |
return "0"; | |
} | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment