out of bound error


  • 0
    N

    bool intervalCompare(Interval a, Interval b) {
    return a.start < b.start;
    }

    class Solution {
    public:

    bool canAttendMeetings(vector<Interval>& intervals) {
        std::sort(intervals.begin(), intervals.end(), intervalCompare);
        for (int i = 0; i < intervals.size() - 1; i++) {
            if (intervals[i].end > intervals[i + 1].start) {
                return false;
            }
        }
        
        return true;
    }
    

    /usr/local/include/c++/6.3.0/debug/vector:415:
    Error: attempt to subscript container with out-of-bounds index 0, but
    container only holds 0 elements.

    Objects involved in the operation:
    sequence "this" @ 0x0x7ffea4ec8160 {
    type = std::__debug::vector<Interval, std::allocator<Interval> >;
    }
    I don't understand why I got this error...
    plz help

    i


Log in to reply
 

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