-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_12915.java
More file actions
22 lines (22 loc) · 769 Bytes
/
_12915.java
File metadata and controls
22 lines (22 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.*;
class Solution {
public String[] solution(String[] strings, int n) {
Arrays.sort(strings, new Comparator<String>(){
@Override
public int compare(String a, String b){
if(a.charAt(n)!=b.charAt(n)) return a.charAt(n)-b.charAt(n);
else{
for(int i=0; i<a.length() && i<b.length(); i++){
if(a.charAt(i)!=b.charAt(i)){
return a.charAt(i)-b.charAt(i);
}
if(i==a.length()-1) return -1;
else if(i==b.length()-1) return 1;
}
};
return 0;
}
});
return strings;
}
}