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;
    }
}