//구글콘솔 광고 추가가
테스트 케이스 추가
Parameters Return
[["00:01", "00:10"], ["00:19", "00:29"]] 2
[["08:00", "08:30"], ["08:00", "13:00"], ["12:30", "13:30"]] 2
[["16:00", "16:10"], ["16:20", "16:30"], ["16:40", "16:50"]] 1
[["09:10", "10:10"], ["10:20", "12:20"], ["12:30", "13:20"]] 1
[["10:00", "10:10"]] 1
호텔 대실

 

내 코드
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution {
    private int StringChangeInt(string str)
    {
        string[] strSplit = str.Split(':');
        return int.Parse(strSplit[0]) * 60 + int.Parse(strSplit[1]);
    }

    public int solution(string[,] book_time) {
        int answer = 0;
        int[] keyArr = new int[book_time.GetLength(0)];
        List<(int, int)> list = new List<(int, int)>();
        List<int> roomCheck = new List<int>();

        for (int i = 0; i < book_time.GetLength(0); i++)
        {
            list.Add((StringChangeInt(book_time[i, 0]), StringChangeInt(book_time[i, 1])));

        }
        var sortlist = list.OrderBy(o => o.Item1);

        foreach((int inRoom, int outRoom) room in sortlist)
        {
            int num = roomCheck.FindIndex(n => n <= room.inRoom - 10);
            if (num == -1)
            {
                roomCheck.Add(room.Item2);
            }
            else
            {
                roomCheck[num] = room.Item2;
            }
        }
        answer = roomCheck.Count;
        return answer;
    }
}
728x90
반응형

+ Recent posts