import java.util.Arrays;
import java.util.stream.*;
class Solution {
int ansIdx=0;
public String[] solution(String[] files) {
// 갱신 배열과 정답 배열
String[] answer = new String[files.length];
String[][] tmpAns = new String[files.length][3];
Arrays.stream(files).forEach(f->{
// 숫자 시작 하는 인덱스와 끝나는 인덱스 투포인터 처럼 찾기
int fIdx = 0;
int fEIdx = 0;
while(!Character.isDigit(f.charAt(fIdx))){
fIdx++;
if(fIdx == f.length()) break;
}
fEIdx = fIdx;
while(Character.isDigit(f.charAt(fEIdx))){
fEIdx++;
if(fEIdx >= f.length()) break;
}
// 갱신배열에 원소삽입
String head = f.substring(0,fIdx);
String num = f.substring(fIdx,fEIdx);
String tail = "";
if(fEIdx<f.length()) tail = f.substring(fEIdx);
tmpAns[ansIdx][0] = head;
tmpAns[ansIdx][1] = num;
tmpAns[ansIdx][2] = tail;
ansIdx++;
});
// head > num 기준으로 sort
Arrays.sort(tmpAns,(o1,o2)->{
if(o1[0].toLowerCase().compareTo(o2[0].toLowerCase()) >0) return 1;
else if(o1[0].toLowerCase().compareTo(o2[0].toLowerCase())<0) return -1;
else{
return Integer.parseInt(o1[1]) - Integer.parseInt(o2[1]);
}
});
ansIdx = 0;
Arrays.stream(tmpAns).forEach(el->{
answer[ansIdx++] = el[0]+el[1]+el[2];
});
// for(int i=0; i<tmpAns.length; i++){
// answer[i] = tmpAns[i][0]+tmpAns[i][1]+tmpAns[i][2];
// }
return answer;
}
}
갱신 배열과 정답 배열을 따로 두어 갱신한다.