1-liner in Ruby


  • 1

    Sort the intervals by start time, then check whether all pairs of consecutive intervals are disjoint.

    def can_attend_meetings(intervals)
      intervals.sort_by(&:start).each_cons(2).all? { |i, j| i.end <= j.start }
    end

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.