Skip to content

Commit b23640b

Browse files
committed
format comment
1 parent 061eb4e commit b23640b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

hi-leetcode/src/main/java/me/meet/leetcode/easy/ReorderDataInLogFiles.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ private ReorderDataInLogFiles() {
1414
* 1. Each word after the identifier will consist only of lowercase letters, or;
1515
* 2. Each word after the identifier will consist only of digits.
1616
* We will call these two varieties of logs letter-logs and digit-logs. It is guaranteed that each log has at least one word after its identifier.
17-
* Reorder the logs so that all of the letter-logs come before any digit-log. The letter-logs are ordered lexicographically ignoring identifier, with the identifier used in case of ties. The digit-logs should be put in their original order.
17+
* Reorder the logs so that all of the letter-logs come before any digit-log. The letter-logs are ordered lexicographically ignoring identifier,
18+
* with the identifier used in case of ties. The digit-logs should be put in their original order.
1819
* Return the final order of the logs.
1920
*
2021
* Example 1:
@@ -28,7 +29,14 @@ private ReorderDataInLogFiles() {
2829
*/
2930
/**
3031
* 题意:Reorder Data in Log Files 日志文件的重新排序
31-
* 思路:这道题让给日志排序,每条日志是由空格隔开的一些字符串,第一个字符串是标识符,可能由字母和数字组成,后面的是日志的内容,只有两种形式的,要么都是数字的,要么都是字母的。排序的规则是对于内容是字母的日志,按照字母顺序进行排序,假如内容相同,则按照标识符的字母顺序排。而对于内容的是数字的日志,放到最后面,且其顺序相对于原顺序保持不变。博主感觉这道题似曾相识啊,貌似之前在很多 OA 中见过,最后还是被 LeetCode 收入囊中了。其实这道题就是个比较复杂的排序的问题,两种日志需要分开处理,对于数字日志,不需要排序,但要记录其原始顺序。这里就可以用一个数组专门来保存数字日志,这样最后加到结果 res 后面,就可以保持其原来顺序。关键是要对字母型日志进行排序,同时还要把标识符提取出来,这样在遍历日志的时候,先找到第一空格的位置,这样前面的部分就是标识符了,后面的内容就是日志内容了,此时判断紧跟空格位置的字符,假如是数字的话,说明当前日志是数字型的,加入数组 digitLogs 中,并继续循环。如果不是的话,将两部分分开,存入到一个二维数组 data 中。之后要对 data 数组进行排序,并需要重写排序规则,要根据日志内容排序,若日志内容相等,则根据标识符排序。最后把排序好的日志按顺序合并,存入结果 res 中,最后别忘了把数字型日志也加入 res,
32+
* 思路:这道题让给日志排序,每条日志是由空格隔开的一些字符串,第一个字符串是标识符,可能由字母和数字组成,后面的是日志的内容,只有两种形式的,要么都是数字的,要么都是字母的。
33+
* 排序的规则是对于内容是字母的日志,按照字母顺序进行排序,假如内容相同,则按照标识符的字母顺序排。而对于内容的是数字的日志,放到最后面,且其顺序相对于原顺序保持不变。
34+
*
35+
* 博主感觉这道题似曾相识啊,貌似之前在很多 OA 中见过,最后还是被 LeetCode 收入囊中了。
36+
* 其实这道题就是个比较复杂的排序的问题,两种日志需要分开处理,对于数字日志,不需要排序,但要记录其原始顺序。这里就可以用一个数组专门来保存数字日志,这样最后加到结果 res 后面,就可以保持其原来顺序。
37+
* 关键是要对字母型日志进行排序,同时还要把标识符提取出来,这样在遍历日志的时候,先找到第一空格的位置,这样前面的部分就是标识符了,后面的内容就是日志内容了,此时判断紧跟空格位置的字符,假如是数字的话,说明当前日志是数字型的,加入数组 digitLogs 中,并继续循环。
38+
* 如果不是的话,将两部分分开,存入到一个二维数组 data 中。之后要对 data 数组进行排序,并需要重写排序规则,要根据日志内容排序,若日志内容相等,则根据标识符排序。
39+
* 最后把排序好的日志按顺序合并,存入结果 res 中,最后别忘了把数字型日志也加入 res,
3240
*/
3341
static String[] reorderLogFiles(String[] logs) {
3442
List<String> res = new ArrayList<>(), digitLogs = new ArrayList<>();

0 commit comments

Comments
 (0)