공부기록
추석트래픽 본문
import java.util.*;
import java.text.SimpleDateFormat;
class Solution {
private boolean check(long s_1, long e_1, long s_2, long e_2){
if(s_2 >= s_1 && s_2 < e_1)
return true;
else if(e_2 >= s_1 && e_2 < e_1)
return true;
else if(s_2 <= s_1 && e_2 >= e_1)
return true;
else
return false;
}
public int solution(String[] lines) {
int answer = 0;
long t_table[][] = new long[lines.length][2];
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
for(int i=0; i<lines.length; i++){
String line = lines[i];
String [] words = line.split(" ");
String s_str = "1970-01-01" + " " + words[1];
String l_str = words[2];
try{
Date date = sdf.parse(s_str);
long e_time = date.getTime();
l_str = l_str.substring(0, (l_str.length())-1);
float tmp_f = Float.parseFloat(l_str);
tmp_f *= 1000;
long tmp_l = (long)tmp_f;
long s_time = e_time - tmp_l + 1;
t_table[i][0] = s_time;
t_table[i][1] = e_time;
}catch(Exception e){
}
}
// Arrays.sort(t_table, (a,b) -> Long.compare(a[0], b[0]));
// for(int i=0; i<t_table.length; i++){
// System.out.println(t_table[i][0] + "~" + t_table[i][1]);
// }
for(int i=0; i<t_table.length; i++){
long s_t = t_table[i][0];
long e_t = t_table[i][1];
int s_idx = 0;
int count = 0;
long threshold = s_t+1000;
while(s_idx < t_table.length){
// if(s_t <= t_table[s_idx][1] && t_table[s_idx][0] <= threshold){
// count++;
// s_idx++;
// }
// else
// break;
if(check(s_t, threshold, t_table[s_idx][0], t_table[s_idx][1])){
count++;
}
s_idx++;
}
if(answer < count)
answer = count;
count = 0;
s_idx = 0;
threshold = e_t+1000;
while(s_idx < t_table.length){
// if(e_t <= t_table[s_idx][1] && t_table[s_idx][0] <= threshold){
// count++;
// s_idx++;
// }
// else
// break;
if(check(e_t, threshold, t_table[s_idx][0], t_table[s_idx][1])){
count++;
}
s_idx++;
}
if(answer < count)
answer = count;
}
return answer;
}
}
2차원 배열에서 arr[0][*]을 정렬하더라도 arr[1][*]는 뒤섞여 있기때문에 모두 check를 돌려야했다.