-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHW_17686.java
More file actions
32 lines (26 loc) ยท 1011 Bytes
/
HW_17686.java
File metadata and controls
32 lines (26 loc) ยท 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class HW_17686 {
public String[] solution(String[] files) {
String regex = "^([^0-9]+)([0-9]{1,5}).*$";
Pattern pattern = Pattern.compile(regex);
Arrays.sort(files, (files1, files2) -> {
Matcher m1 = pattern.matcher(files1);
Matcher m2 = pattern.matcher(files2);
if(m1.find() && m2.find()){
String h1 = m1.group(1).toLowerCase(); // ๋์๋ฌธ์ ๊ตฌ๋ถX
String h2 = m2.group(1).toLowerCase();
int head = h1.compareTo(h2);
if(head!=0){
return head;
}
int n1 = Integer.parseInt(m1.group(2));
int n2 = Integer.parseInt(m2.group(2));
return Integer.compare(n1, n2); // number ๊ธฐ์ค ์ ๋ ฌ
}
return 0; // ๊ฐ์ ํ์ผ๋ช
์ ๊ทธ๋๋ก ์ ์งํ๊ธฐ
});
return files;
}
}