Algorithm/Programmers
[Java] ํ๋ก๊ทธ๋๋จธ์ค - ์ถ์ ํธ๋ํฝ
๊ฐ๋ฐ๊ฐ๊ตด๐ธ
2022. 6. 13. 21:30
[๋ฌธ์ ]



[ํ์ด]
๊ฐ ์ ๋ ฅ์ ์์์๊ฐ~๋๋์๊ฐ์ 0.001์ด ๋จ์๋ก ๋ชจ๋ ํ์ธํ์์ง๋ง ์ญ์๋ ์๊ฐ์ด๊ณผ์๊ณ ๊ฒฐ๊ตญ ํด๋น ๋ธ๋ก๊ทธ๋ฅผ ์ฐธ๊ณ ํ์ฌ ํ์ด๋ฅผ ์งํํ์์ต๋๋ค.
https://geunzrial.tistory.com/26
ํ๋ก๊ทธ๋๋จธ์ค 3๋จ๊ณ ์ถ์ํธ๋ํฝ[java]
๋ฌธ์ ์ด๋ฒ ์ถ์์๋ ์์คํ ์ฅ์ ๊ฐ ์๋ ๋ช ์ ์ ๋ณด๋ด๊ณ ์ถ์ ์ดํผ์น๋ ์๋ฒ๋ฅผ ์ฆ์คํด์ผ ํ ์ง ๊ณ ๋ฏผ์ด๋ค. ์ฅ์ ๋๋น์ฉ ์๋ฒ ์ฆ์ค ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ๊ธฐ ์ํด ์๋ ์ถ์ ๊ธฐ๊ฐ์ธ 9์ 15์ผ ๋ก๊ทธ ๋ฐ์ดํฐ๋ฅผ
geunzrial.tistory.com
ํ์ด๋ฅผ ๋ณด๊ณ ๋๋ ์ ์ด์ log๊ฐ ๋๋์๊ฐ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ๋์ด ๋ค์ด์ค๊ธฐ ๋๋ฌธ์ ์ดํ์ log๋ค์ค ๋ช๊ฐ์ ๊ฒน์น๋์ง ๊ตฌํ๋ฉด ๋๋ ๊ฐ๋จํ ๋ฌธ์ ์์ต๋๋ค.
[์ฝ๋]
import java.util.*;
class Solution {
public static int[] start;
public static int[] end;
public static int max = 0;
public static int N;
public int solution(String[] lines) {
int answer = 0;
N = lines.length;
start = new int[N];
end = new int[N];
for(int i=0;i<lines.length;i++) {
String[] str = lines[i].split(" ");
double time = doubleTime(str[1]);
double sec = Double.parseDouble(str[2].substring(0,str[2].length()-1));
double s = time - sec + 0.001;
start[i] = (int)(s*1000);
end[i] = (int)(time*1000) + 1000;
}
for(int i=0;i<N;i++) {
int cnt = 0;
for(int j=i;j<N;j++) {
if(end[i] > start[j]) {
cnt++;
}
}
if(answer < cnt) {
answer = cnt;
}
}
return answer;
}
public static double doubleTime(String s) {
String[] str = s.split(":");
double time = Double.parseDouble(str[0])*3600 + Double.parseDouble(str[1])*60 + Double.parseDouble(str[2]);
return time;
}
}