12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- func getSkyline(buildings [][]int) [][]int {
- return [][]int{}
- }
- type SortedList struct {
- List []int
- Len int
- }
- func (sl SortedList) Search(x int) int {
- beg, end := 0, sl.Len
- for beg < end {
- mid := beg + (end-beg)/2
- if x < sl.List[mid] {
- end = mid
- } else if sl.List[mid] < x {
- beg = mid + 1
- } else {
- return mid
- }
- }
- return beg
- }
- func (sl *SortedList) Insert(x int) {
- idx := sl.Search(x)
- sl.List = append(sl.List, 0)
- copy(sl.List[idx+1:], sl.List[idx:])
- sl.List[idx] = x
- sl.Len++
- }
- func (sl *SortedList) Delete(x int) {
- idx := sl.Search(x)
- copy(sl.List[idx:], sl.List[idx+1:])
- sl.List = sl.List[:sl.Len-1]
- sl.Len--
- }
- type PQ struct {
- Queue []Item
- Len int
- }
- type Item interface {
- Less(than Item) bool
- }
- func (pq PQ) Len() int { return pq.Len }
- func (pq PQ) Less(i, j int) bool { return pq.Queue[i].Less(pq.Queue[j]) }
- func (pq PQ) Swap(i, j int) { pq.Queue[i], pq.Queue[j] = pq.Queue[j], pq.Queue[i] }
- func (pq *PQ) Enqueue(item Item) {
- pq.Queue = append(pq.Queue, item)
- pq.Len++
- pq.swim(pq.Len)
- }
- func (pq *PQ) Dequeue() Item {
- pq.Swap(1, pq.Len)
- pq.Queue = pq.Queue[:pq.Len]
- pq.Len--
- pq.sink(pq.Len)
- }
- func (pq PQ) swim(i int) {
-
- }
- func (pq PQ) sink(i int) {
-
- }
|