File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ function merge ( intervals : number [ ] [ ] ) : number [ ] [ ] {
2+ const a = [ ]
3+ for ( const [ s , e ] of intervals ) {
4+ a . push ( [ s , 1 ] , [ e , - 1 ] )
5+ }
6+ a . sort ( ( x , y ) => {
7+ if ( x [ 0 ] === y [ 0 ] ) {
8+ return - ( x [ 1 ] - y [ 1 ] )
9+ }
10+ return x [ 0 ] - y [ 0 ]
11+ } )
12+ let cnt = 0 , ans = [ ] , tmp = [ ]
13+ for ( const t of a ) {
14+ cnt += t [ 1 ]
15+ if ( t [ 1 ] === 1 && cnt === 1 ) {
16+ tmp . push ( t [ 0 ] )
17+ } else if ( cnt === 0 ) {
18+ tmp . push ( t [ 0 ] )
19+ ans . push ( tmp )
20+ tmp = [ ]
21+ }
22+ }
23+ return ans
24+ } ;
Original file line number Diff line number Diff line change 3636 - [ 字符串哈希] ( #字符串哈希 )
3737 - [ 括号匹配] ( #括号匹配 )
3838 - [ 分治 (Divide and Conquer)] ( #分治-divide-and-conquer )
39+ - [ 扫描线 (Sweep Line)] ( #扫描线-sweep-line )
3940 - [ Links] ( #links )
4041
4142## Problems
266267- 315 . Count of Smaller Numbers After Self
267268- 2179 . Count Good Triplets in an Array
268269
270+ ### 扫描线 (Sweep Line)
271+
272+ - 56 . Merge Intervals
273+
269274## Links
270275
271276- https://wisdompeak.github.io/lc-score-board/
You can’t perform that action at this time.
0 commit comments