注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 匿名 于 2021-12-19 00:27 编辑
几分钟前刚刚做完香蕉的OA第一题 是写一个comparator
Your team at Amazon has been contracted by a telecommunications company that is trying to upgrade junction boxes all over Techlandia. Some of the junction boxes have already been upgraded, and other boxes have not. Your task is to identify the oldest boxes that need to be upgraded first but leaving the newer model boxes so that they will not be prioritized.
All the junction boxes are identified by an alphanumeric identifier, followed by space delimited version information. The older generation uses space delimited lowercase English strings to identify the version, but the newer generation uses space delimited positive integers to identify the version. Your task is to sort the junction boxes in the following order:
1. The older generation junction boxes should be returned first, sorted by lexicographic ordering of alphabetic version.
2. If there are any ties in the older generation, ties should be broken by the alphanumeric identifier.
3. The newer generation boxes must all come after the older generation, in the original order they were given in the input.
Write a function or method to return a list of strings representing the correctly prioritized
orders according to this system.
Input
The input to the function/method consists of one
argument:
boxList, a list of strings representing all of the
identifiers and version information.
Output
Return a list of strings representing the correctly
prioritized orders according to this system.
Examples
Input:
boxList=
[vkc 82 011
[Leo first qpx]
[09z cat hamster]
[06f 12 25 61
[azO first qpx]
[236 cat dog rabbit snake]
Output:
[236 cat dog rabbit snake]
[09z cat hamster]
[azo first qpx]
[eo first qpx]
[ykc 82 01]
[06f 12 25 6]
Explanation:
The four old generation junction boxes should
come first, with the "cat dog rabbit snake" box
coming before the "cat hamster type". Since the
two boxes of type "first qpx" have the same
version information, they should come next, using
the "azo" identifier to come before the "eo"
identifier. Finally, the already upgraded junction
boxes should come last, in the original order, they
were provided in the file.
public static List‹String› sortBoxes (List‹String› boxList)
第二题我没想到更好的办法做,就写了Brute Force, 有些test超时了
没有截图,但是题目大概是给一个数组int[] eg.[3,5,-2], output List<Long>
|