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);

时间: 2024-08-26 14:13:25

zenefits oa - sort integer array in lexographical order的相关文章

Minimum number of swaps required to sort an array

https://www.hackerrank.com/challenges/minimum-swaps-2/problem Minimum Swaps II You are given an unordered array consisting of consecutive integers  [1, 2, 3, ..., n] without any duplicates. You are allowed to swap any two elements. You need to find t

[Swift]LeetCode912.排序数组 | Sort an Array

原文链接:https://www.cnblogs.com/strengthen/p/10886335.html Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1] Output: [1,2,3,5] Example 2: Input: [5,1,1,2,0,0] Output: [0,0,1,1,2,5]  Note: 1 <= A.length <= 1

LeetCode-912.Sort an Array

Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1] Output: [1,2,3,5] Example 2: Input: [5,1,1,2,0,0] Output: [0,0,1,1,2,5]  Note: 1 <= A.length <= 10000 -50000 <= A[i] <= 50000 排序 参考https://www.cnbl

[LeetCode] 912. Sort an Array 数组排序

Given an array of integers?nums, sort the array in ascending order. Example 1: Input:?[5,2,3,1] Output: [1,2,3,5] Example 2: Input: [5,1,1,2,0,0] Output: [0,0,1,1,2,5] Note: 1 <= A.length <= 10000 -50000 <= A[i] <= 50000 Github 同步地址: https://g

Sort the Array

Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array,

Codeforces Round #258 (Div. 2) B. Sort the Array

Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array,

Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)

题目链接:http://codeforces.com/contest/451/problem/B ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943/ma

(周日赛)Sort the Array

题意:一段数字,逆置其中两个使其递增 DescriptionBeing a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of ndistinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agre

CodeForces 451B Sort the Array

Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a b