码迷,mamicode.com
首页 > 其他好文 > 详细

252. Meeting Rooms

时间:2020-03-01 00:30:35      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:and   interval   col   rip   art   ==   leetcode   ini   style   

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

标签:and   interval   col   rip   art   ==   leetcode   ini   style   

原文地址:https://www.cnblogs.com/johnnyzhao/p/12387309.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!