Created
May 12, 2015 23:49
-
-
Save svpino/03892b9c49cad69e0b21 to your computer and use it in GitHub Desktop.
Problem 4 in "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
This file contains 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
import java.util.Arrays; | |
import java.util.Comparator; | |
// Solution to Problem 4 posted in "Five programming problems every Software Engineer should be able to solve in less than 1 hour" | |
// Original post: https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour | |
public class Main { | |
private static Integer[] VALUES = { 5, 2, 1, 9, 50, 56 }; | |
public static void main(String[] args) { | |
Arrays.sort(VALUES, new Comparator() { | |
@Override | |
public int compare(Integer lhs, Integer rhs) { | |
String v1 = lhs.toString(); | |
String v2 = rhs.toString(); | |
return (v1 + v2).compareTo(v2 + v1) * -1; | |
} | |
}); | |
String result = ""; | |
for (Integer integer : VALUES) { | |
result += integer.toString(); | |
} | |
System.out.println(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment