1. Description:
Notes:
2. Examples:
3.Solutions:
1 /** 2 * Created by sheepcore on 2018-11-11 3 */ 4 class Solution { 5 public String[] reorderLogFiles(String[] logs) { 6 Comparator<String> myComp = new Comparator<String>() { 7 @Override 8 public int compare(String s1, String s2) { 9 int s1si = s1.indexOf(' '); 10 int s2si = s2.indexOf(' '); 11 char s1fc = s1.charAt(s1si+1); 12 char s2fc = s2.charAt(s2si+1); 13 14 if (s1fc <= '9') { 15 if (s2fc <= '9') return 0; 16 else return 1; 17 } 18 if (s2fc <= '9') return -1; 19 20 int preCompute = s1.substring(s1si+1).compareTo(s2.substring(s2si+1)); 21 if (preCompute == 0) return s1.substring(0,s1si).compareTo(s2.substring(0,s2si)); 22 return preCompute; 23 } 24 }; 25 Arrays.sort(logs, myComp); 26 return logs; 27 } 28 }