Golang beats 100% so far


  • 0
    R
    func canAttendMeetings(intervals []Interval) bool {
        sort.Sort(Cp(intervals))    
        n:= len(intervals)
        for i:= 0; i < n -1; i++ {
            if intervals[i].End > intervals[i+1].Start {
                return false
            }
        }
        return true
    }
    
    type Cp []Interval
    
    func (a Cp) Len() int           { return len(a) }
    func (a Cp) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
    func (a Cp) Less(i, j int) bool { return a[i].Start < a[j].Start }
    

Log in to reply
 

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