252. Meeting Rooms

Posted johnnyzhao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了252. Meeting Rooms相关的知识,希望对你有一定的参考价值。

import java.util.Arrays

/**
 * 252. Meeting Rooms
 * (Locked by Leetcode)
 * https://www.lintcode.com/problem/meeting-rooms/description
 * Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei),
 * determine if a person could attend all meetings.
 * */

class Interval(start: Int, end: Int) {
    var start = 0
    var end = 0
    init {
        this.start = start
        this.end = end
    }
}

class Solution {
    fun canAttendMeetings(intervals: List<Interval>?): Boolean {
        if (intervals == null) {
            return false
        }
        val size = intervals.size
        val starts = IntArray(size)
        val ends = IntArray(size)
        for (i in 0 until size) {
            starts[i] = intervals[i].start
            ends[i] = intervals[i].end
        }
        Arrays.sort(starts)
        Arrays.sort(ends)
        for (i in 1 until size) {
            if (ends[i - 1] > starts[i]) {
                return false
            }
        }
        return true
    }
}

 

以上是关于252. Meeting Rooms的主要内容,如果未能解决你的问题,请参考以下文章

252 Meeting Rooms

[LC] 252. Meeting Rooms

252.Meeting Rooms

Leetcode 252, 253. Meeting Rooms

LeetCode 252. Meeting Rooms (会议室)

LeetCode Meeting Rooms