O(n2)


  • 0
    M
    /**
     * Definition for an interval.
     * struct Interval {
     *     int start;
     *     int end;
     *     Interval() : start(0), end(0) {}
     *     Interval(int s, int e) : start(s), end(e) {}
     * };
     */
    class Solution {
    public:
        bool canAttendMeetings(vector<Interval>& intervals) {
              int size = intervals.size();
              if(size <= 1) return true;
             
              for(int i = 0; i < size; i++)
              {
                for(int j = i+1; j < size; j++)
                {
                  if(doesConflict(intervals[i], intervals[j]))
                    return false;
                }
              }
              
              return true;   
        }
        
    private:
        bool doesConflict(Interval &m1, Interval &m2) {
          return !( (m1.start >= m2.end) || (m2.start >= m1.end) );
        }
    
    };
    

Log in to reply
 

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