Skip to content

Commit

Permalink
ReorderLogFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
silenceleaf committed Jun 17, 2019
1 parent 03c5b71 commit 9787e26
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/org/zjy/learn/code/amazon/ReorderLogFiles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class ReorderLogFiles {
public String[] reorderLogFiles(String[] logs) {
Arrays.sort(logs, (a, b) -> {
String[] split1 = a.split(" ", 2);
String[] split2 = b.split(" ", 2);
boolean isDigit1 = Character.isDigit(split1[1].charAt(0));
boolean isDigit2 = Character.isDigit(split2[1].charAt(0));
if(!isDigit1 && !isDigit2) {
int comp = split1[1].compareTo(split2[1]);
if(comp != 0)
return comp;
else
return split1[0].compareTo(split2[0]);
}
return isDigit1 ? (isDigit2 ? 0 : 1) : -1;
});
return logs;
}
}

0 comments on commit 9787e26

Please sign in to comment.