Skip to content

Commit

Permalink
Update min-meeting-room.js
Browse files Browse the repository at this point in the history
Improve the implementation of a merge Interval.  Tested with 

```go
...
func main() {
    rooms := minMeetingRooms([]Interval{
                Interval{
                    start: 0,
                    end: 5,
                },
                Interval{
                    start: 4,
                    end: 7,
                },
                Interval{
                    start: 2,
                    end: 10,
                },
                Interval{
                    start: 4,
                    end: 3,
                },
                Interval{
                    start: 9,
                    end: 19,
                },
                Interval{
                    start: 3,
                    end: 14,
                },
             })

    fmt.Println(rooms)
}
```

and result : 

```bash
go run min-meeting-room.go

4
```
  • Loading branch information
kounkou authored Nov 25, 2024
1 parent ca62a28 commit a20b428
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions logic/intervals/min-meeting-room.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@ var question = [
return rooms;
}
`,
answerGo: `func minMeetingRooms(intervals [][]int) int {
if len(intervals) == 0 {
return 0
}
answerGo: `type Interval struct {
start int
end int
}
startTimes := make([]int, len(intervals))
endTimes := make([]int, len(intervals))
func minMeetingRooms(intervals []Interval) int {
startTimes := make([]int, 0)
endTimes := make([]int, 0)
for i, interval := range intervals {
startTimes[i] = interval[0]
endTimes[i] = interval[1]
for _, v := range intervals {
startTimes = append(startTimes, v.start)
endTimes = append(endTimes, v.end)
}
sort.Ints(startTimes)
sort.Ints(endTimes)
sort.Slice(startTimes, func(i, j int) bool {
return startTimes[i] > startTimes[j]
})
sort.Slice(endTimes, func(i, j int) bool {
return endTimes[i] > endTimes[j]
})
rooms := 0
j := 0
Expand Down

0 comments on commit a20b428

Please sign in to comment.