252. Meeting Rooms

Source: Internet
Author: User

Make intervals a ArrayList and then re-write your own comparator, sort intervals, sort by start time, sort by end time if the start time is the same

Finally, check all the interval, if the previous end time is after the beginning of this one, then return false. If it's done, then it's true.

If the list length is 1, then surely true does not require a separate check

1      Public Booleancanattendmeetings (interval[] intervals) {2List<interval> intervallist =NewArraylist<interval>(Arrays.aslist (intervals));3Collections.sort (Intervallist,NewComparator<interval>() {4              Public intCompare (Interval O1, Interval O2) {5                 if(O1.start! =O2.start) {6                     returnO1.start-O2.start;7}Else {8                     returnO1.end-O2.end;9                 }Ten             } One         }); A          for(inti = 1; i < intervals.length; i++) { -             if(Intervallist.get (i-1). End >Intervallist.get (i). Start) { -                 return false; the             } -         } -         return true; -}

252. Meeting Rooms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.