problem0352

package
v0.0.0-...-db5e768 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2019 License: MIT Imports: 1 Imported by: 0

README

352. Data Stream as Disjoint Intervals

题目

Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a list of disjoint intervals.

For example, suppose the integers from the data stream are 1, 3, 7, 2, 6, ..., then the summary will be:

[1, 1]
[1, 1], [3, 3]
[1, 1], [3, 3], [7, 7]
[1, 3], [7, 7]
[1, 3], [6, 7]

Follow up: What if there are lots of merges and the number of disjoint intervals are small compared to the data stream's size?

Credits:Special thanks to @yunhong for adding this problem and creating most of the test cases.

解题思路

见程序注释

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interval

type Interval = kit.Interval

*

  • Definition for an interval.
  • type Interval struct {
  • Start int
  • End int
  • }

type SummaryRanges

type SummaryRanges struct {
	// contains filtered or unexported fields
}

func Constructor

func Constructor() SummaryRanges

* Initialize your data structure here.

func (*SummaryRanges) Addnum

func (sr *SummaryRanges) Addnum(val int)

func (*SummaryRanges) Getintervals

func (sr *SummaryRanges) Getintervals() []Interval

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL