zenefits oa - sort integer array in lexographical order

[ 12 | 2434 | 23 | 1 | 654 | 222 | 56 | 100000 ]

Then the output should be:

[ 1 | 100000 | 12 | 222 | 23 | 2434 | 56 | 654 ]

建立自己的comparator:

Comparator<Integer> intLexCompare = new Comparator<Integer>() {
  int compareTo( Integer x, Integer y) {
      return x.toString().compareTo(y.toString();
  }
}  

Arrays.sort(nums, intLexCompare);

你可能感兴趣的:(zenefits oa - sort integer array in lexographical order)